awk - treat multiple delimiters as one

Is there anyway to get awk to treat multiple delimiters as one? Particularly spaces...

okay.... figured this out....:o

awk -F" +"

trailing + will mean one or more - if you're interested!

not sure why you would have to specify multiple spaces as a delimiter. awk's default delimiter is a space.

[hostname]/export/home/optimus$echo 'this   is a test'|awk '{ print $1 $2 $3 }'
thisisa
[hostname]/export/home/optimus$

I see..... yes that's quite good.... but I'm a little confused now. I see that the default is to use either tab or space....and that it by default treats these consecutively as one. But with other delimiters that I specify it didn't seem to work....

i..e

1|2|3|4
1||2||3
1|||||2|||||3

###FIRST
$ awk -F"|+" ' { print $1,$2,$3} ' my_file
1 2 3
1 2
1
##SECOND
$ awk -F"|" ' { print $1,$2,$3} ' my_file
1 2 3
1 2
1

It should work if you add brackets around the delimiter:

In a script:
awk -F"[|]+" ' { print $1,$2,$3} ' my_file

From the command line:
echo '1||2|3|4'|awk -F"[|]+" '{print $1,$2,$3}'

Cool! And it even works with different multiples of a delimiter.

# cat myfile
1|||2||||3|||||4

# awk -F"[|]+" ' { print $1,$2,$3,$4} ' myfile
1 2 3 4

Awesome!!
:smiley: :cool:

beaming at the praise :smiley: :wink: