Mark Z.
Mark Z.

Reputation: 655

Multiple field seperators each of which appears multiple times using awk

I am trying to separate fields using awk but have met some problems when I have multiple separators each of which appears multiple times.

For example, if I type

echo "aa@@#####=#3413.5" | awk -F "#+|@+|=" '{print $1","$2","$3","$4","$5}'

then the results are:

aa,,,,3413.5

but what I want is

aa,3413.5

I have searched online for a long time, but other questions are related to either multiple separators appearing one time for each, i.e. "@|#", or a single separator appearing multiple times, i.e. "@+".

Anyone has ideas about how to separate fields in my case?

Thanks a lot!

Upvotes: 2

Views: 63

Answers (1)

ymonad
ymonad

Reputation: 12090

awk -F '[@#=]+'

seems to work.

awk -F "#+|@+|=" 

this one matches only for string like #####, @@@@, or =.

see following URL for detail:

http://www.math.utah.edu/docs/info/gawk_5.html#SEC28

Upvotes: 4

Related Questions