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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FS = "\t" doesn't work with nawk

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
A script I try to use reads fields separated with \t from a file. The script uses nawk and in the script the field separator is set to FS="\t". However when I run it, this doesn't work, the fields are not separated. I've changed the field separator in the script and the file to * instead and then it works. What could be wrong?

Best regards
-Palle Zetterstrand
Palle.Zetterstrand@emw.ericsson.se
 
It could be that the output field separator ( OFS )
defaults to a space, so that even though you set the
FS to a tab the output is separated by a space.

Try this: FS = OFS = "\t"

This should retain the tabs in your output the same
as in your input.

Hope this helps you.

 
It was even simpler. The echo command that created the file put \t between the fields instead of tabs. I didn't see this at first. Maybe /usr/ucb/echo was used instead of /usr/bin/echo, when I changed to /usr/bin/echo it worked. As a UNIX newbie I learn stuff everyday... thanks for the help

-Palle Zetterstrand
 
Yeah, the ucb stuff can sometimes mess things up.

The best way I have found to handle this is to
put this line into your .cshrc as the last line
in the file:

set path = ($path /usr/ucb)

Of course, take any reference to ucb stuff out of
the direct path so this can be appended as the very
last directory searched. This should find the
/usr/bin stuff first without doing without the ucb
stuff should you need any progs included in ucb.

Glad you worked it out.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top