How to `cut` a String Using a String as the Delimiter in Bash?
Posted on In QAIs is possible to cut
in Linux using a string as the delimiter?
cut --delimiter="delim" -f 1,3
cut
reports:
cut: the delimiter must be a single character
The most closest solution that I find is using awk
/gawk
:
awk -F 'delim' '{print $1; print $3}'
From the manual:
-F fs
–field-separator fs Use fs for the input field separator (the value of the FS predefined variable).
An you can also use regular expression for the delimiter (field separator):
Similarly, if the FPAT variable is set to a string representing a
regular expression, each field is made up of text that matches that
regular expression. In this case, the regular expression describes the
fields themselves, instead of the text that separates the fields.
Assigning a new value to FS or FIELDWIDTHS overrides the use of FPAT.
I cant use awk ffs