How can I use double character delimiter in the cut command

Hi All,

Can the cut command have double character delimiter?

If yes, how can we use it.

if my data file contains :

apple || mango || grapes

i used

cut -f1 -d"||" filename

but got an error.

Plz help....

Thanks.

Hi.

Standard cut accepts a single character for a delimiter. The awk interpreter allows a regular expression to be specified. So, for example, you could approximate the cut of field 2 of your sample data with:

#!/usr/bin/env sh

# @(#) a1       Demonstrate awk field splitting with a regular expression.

set -o nounset
echo

## Use local command version for the commands in this demonstration.

echo "(Versions used in this script displayed with local utility "version")"
version bash awk cat

echo
echo " Results of printing field 2, as cut might do it:"

awk '
BEGIN   { FS = " *[|][|] *" }
        { print $2 }
' data1 |
cat -vet

exit 0

Producing:

% ./a1

(Versions used in this script displayed with local utility version)
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
GNU Awk 3.1.4
cat (coreutils) 5.2.1

 Results of printing field 2, as cut might do it:
mango$

You could remove the " *" from the regular expression, but then you would get extra spaces around the output fields ... cheers, drl