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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to replace str1 with str2 in the nth field

Status
Not open for further replies.

KathyJones

Programmer
Aug 16, 2001
15
US
Hi,
I have a text file like

ID name abc member? score present?
10034 abc yes 876 yes
10035 xyz yes 373 No
10036 mno 372 yes

How can I replace the "yes"s under the abc member field to "abc"? Should I use awk and sed together?? If so how??
Please help.

K.


 
Hi Kathy,

Given your example this should do it:

awk '/^[0-9]+/ {

if($3 ~ /yes/) $3 = "abc"

}' infile > outfile

This limits the action to only lines that begin with one or more numbers and tests field 3 for a match on "yes". If so, it replaces "yes" with "abc".

Hope this helps,
Jesse

flogrr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top