File Manipulations

Hi All,

I have a pipe delimited file with around 30 fields. What is the simple way to Update a value for any column. For ex. If i want to update 22 field with "album".

Similarly, how to do this for the whole file and selective records of the file.

Example file contents:

f1,f2,f2,f4,f5,f6
11,  ,  ,22,33,44
11,  ,  ,22,33,44
11,  ,  ,22,33,44
11,  ,  ,22,33,44
11,  ,xx,22,33,44
  1. How to update f2 value with "ZZ"
  2. How to do the same for only selective records say only for first 3 lines.

Thanks in Advance.

Regards,
Joe

Joe2226,

You can try with.

awk 'BEGIN{FS=OFS=","} {$2="ZZ"}1' file
awk 'BEGIN{FS=OFS=","} NR<4{$2="ZZ"}1' file

I hope it helps.

hi cgkmal,
I tried the code, I'm geting an error, its givin me syntax error & bailing out error. I dnt know wat does tht mean...

Hi.

It probably means you are using Solaris, and should use /usr/xpg4/bin/awk or nawk

okay alrite... I'm using SunOS.
M very new to Unix n jus trying to learn as much as i can from this forum.
M sure the syntax will still remain the same with nawk as well right..??

---------- Post updated at 03:47 AM ---------- Previous update was at 03:45 AM ----------

Thanx scottn it worked wid nawk.

I got the following output:

f1,ZZ,f2,f4,f5,f6
11,ZZ, ,22,33,44
11,ZZ, ,22,33,44
11,ZZ, ,22,33,44
11,ZZ, ,22,33,44
11,ZZ,xx,22,33,44
,ZZ  <---  Where does this come from..??
f1,ZZ,f2,f4,f5,f6
11,ZZ, ,22,33,44
11,ZZ, ,22,33,44
11, , ,22,33,44
11, , ,22,33,44
11, ,xx,22,33,44