Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nawk problem on more than one separators 1

Status
Not open for further replies.

oceandeep

IS-IT--Management
Jul 6, 2000
69
GR
Hi,

I am having a problem with nawk when using -F with more than one separators.
OS: Sun OS 5.8
sh: bourne shell
line to be parsed in file:
test = 2

when I use `nawk -F'[ =]' '{ print $0, NF }' file`
it showed: test = 2 4
and if I tried `nawk -F'[ =]' '{ print $1, $2, $3, $4 }' file`
it showed: test 2
I am quite dummy about nawk, but from my understanding, when we define like -F'[ =]', both space and "=" will be the delimiters, so the NF should be 2 instead of 4, and the second element $2 should be 2 in this example. But the actual result showed that 2 is the forth element $4!
Can anybody here teach me the right way on how to use nawk with more than one separators?
Thanks in advance!

Jiang
 
You can specify multiple field separators with -F '[ =]*'
Without the "*" you are specifying FS to be a single space or a single "=".
 
That's magic! It worked! But from the book I am reading, they never mentioned about the use of "*" and from their examples, -F'[ =]' should work out the way that I want, that wasted me to much time!
Thank you very much, buddy!

Jiang
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top