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!

changing column values - sed/awk?

Status
Not open for further replies.

colsablue

Programmer
Apr 19, 2004
3
GB
Please help - need a quick program to change the 3rd column from whatever to another value, globally - does anyone know how to do this qiuckly?

02 1314 4 100 39
02 1315 4 091 01 1 1
02 1315 4 091 05 549
02 1316 4 091 10 0 3

Thanks
 
nawk -v col=3 -v new=15 -f colsa.awk colsa.txt

#-------- colsa.awk
{
$col = new; print
}


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Cheers mate, thanks. Do you know how to do it if the original is had 'tabs' instead of 'spaces' between the columns?

Thanks again
 
nawk -v OFS=$(echo '\t') -v col=3 -v new=15 -f colsa.awk colsa.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Succinct:
[tt]
awk -f colsa.awk OFS="\t" col=3 new=15 colsa.txt
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top