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!

Change delimiter

Status
Not open for further replies.

ravioli

Programmer
Mar 30, 2004
39
US
Hello All,

I am having trouble with what seems simple. I am trying to change the delimiters in a file using awk. The current delimiter is a tab and I would like to change it to a ":" (colon).

I am on the Korn shell and have tried the following:

awk -F: {print} filename

and also:

awk 'BEGIN { OFS=FS = ":" }
{ print }' datafile

I have also tried some other permutations of the above. I know I am close. Any ideas?

Ravioli

 
nawk -v OFS=':' '$0=$0' datafile

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
ooops, sorry!

nawk -v OFS=':' '$1=$1' datafile

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Vlad,

Thanks for your help.
What is the difference between nawk and awk?

Bradley
 
nawk stands for NewAWK.

Under Solaris (and some other OS's - HO-UX I think as well], the /usr/bin/awk is the OLD (circa '1980s') version of awk. The 'nawk' is newer and provides some additional functionality.

You might find the following links useful:



vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Vlad,

Thanks again, it worked great. I am working on a Solaris Box.

Bradley
 
on Solaris don't use /usr/bin/awk - it's an OLD-OLD-OLD awk.

use either /usr/bin/nawk OR a POSIX compliant /usr/xpg4/bin/awk

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
The AIX version of awk doesn't reevaluate $0 when it do [tt]$1=$1[/tt].
The syntax that must be used is [tt]$1=$1""[/tt]

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top