Changing Field Separaton in NAWK

Posted on 2004-10-06
Last Modified: 2006-11-17

I have a tab delimited file called 'data.5'.  I need to change it from tab delimited to ':' delimited.


nawk -F ":" { print } data.5 >

Where am I going wrong?

Question by:elwayisgod
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4

Author Comment

ID: 12245617
I'm getting closer,  however this just puts the colons on the end.  Can I even do this with NAWK?

nawk -F: '{ print $1"\:",$2"\:",$3"\:",$4 }' data.5 >

broncos:/Users/stoteve/regis/week5 46 % more
Dunny      John      303-555-1212      Utah: : :
Knox      Bill      402-498-7890      Nebraska: : :
Jones      Mary      908-456-1243      Montana: : :
Smith      Barb      319-456-2390      Utah: : :
Utah      Hank      301-494-1009      Wyoming: : :
LVL 21

Expert Comment

ID: 12246200
nawk -F "\t" { print } data.5 >
(-F is the file seperator char used in the _input_ file)

syntax is fine
LVL 21

Expert Comment

ID: 12246222
As for
nawk -F: '{ print $1"\:",$2"\:",$3"\:",$4 }' data.5 >

Two things:
It's looking for an IFS of ":"; And doesn't find it, so $1 is the whole line, "Dunny     John     303-555-1212     Utah"; $2-4 are undefined.

Plus, if you seperate the output fields with "," nawk will substitute the OFS anyway; So you would get
LVL 21

Expert Comment

ID: 12246256
Tested with Gnu awk, but I'm confident it will work with nawk ;-)

awk -F"\t" 'BEGIN {OFS=":"} {print $1,$2,$3}' data.5 >
LVL 21

Accepted Solution

tfewster earned 50 total points
ID: 12246269
Oops, missed $4
awk -F"\t" 'BEGIN {OFS=":"} {print $1,$2,$3,$4}' data.5 >

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question