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!

Substitute in column 4 2

Status
Not open for further replies.
Oct 10, 2003
2,323
US
I want to change every occurence of I (Insert) to U (Update) in column 4 of every row in a Newline record delimited file (ordinary unix file). Can anyone help with sed or awk?

-------------------------
The trouble with doing something right the first time is that nobody appreciates how difficult it was - Steven Wright
 
Something like this ?
awk '$4=="I"{$4="U"}1' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks, but this is not quite working. When I get it working in my Solaris environment, I will post the working solution here.

-------------------------
The trouble with doing something right the first time is that nobody appreciates how difficult it was - Steven Wright
 
In solaris use nawk.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
nawk `$4=="I" {$4="U"} 1` infile > outfile

is not changing anything in outfile, although all rows are copied.

-------------------------
The trouble with doing something right the first time is that nobody appreciates how difficult it was - Steven Wright
 
I wonder about the backquote, ie ` vs '
Anyway, why not post some samples input record and elaborate on the field separator ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Here's the error using even a different delimiter in the awk command.

nawk \$4=="I"{$4="U"} /data/etl112/load/IdsClmClm>
nawk: syntax error at source line 1
context is
>>> $4==I{= <<< U}1 /data/etl112/load/IdsClmClmPedestrianFkey.dat111
nawk: illegal statement at source line 1

Also, here's a sample of the data. It is pipe delimited, but the absolute column 4 is what I want to change (delimited column 2)

0|"I"|"N"|"Y"|"2006-03-1recordcontinuestonewline
0|"I"|"N"|"Y"|"2006-03-16 11.55.01.recordcontinues
0|"I"|"N"|"Y"|"2006-03-16 11.55

-------------------------
The trouble with doing something right the first time is that nobody appreciates how difficult it was - Steven Wright
 
nawk 'BEGIN{FS=OFS="|"}$2=="\"I\""{$2="\"U\""}1' /data/etl112/load/IdsClmClmPedestrianFkey.dat111

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yes. Most gracious of you to help reduce the time I will be spending rerunning stuff this weekend.

Still would like to know how to do a direct substitution in column 4 of $0 - maybe when I'm done with the rerun.

Thanks again PHV.

-------------------------
The trouble with doing something right the first time is that nobody appreciates how difficult it was - Steven Wright
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top