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

Adding a field for selective lines 1

Status
Not open for further replies.

arunrr

Programmer
Oct 2, 2009
103
US
Hello,

From input data (sample shown below, actual input is about 300 lines), i need to add a 5th field, ICC Cricket World Cup warm-up, for lines that only have 4 fields.

I am using...
cat inputfile | awk -F, '{if (NF==4) printf ($0", ICC Cricket World Cup warm-up\n"); else printf $0"\n"}'

The trick however is that i only need t do this for matches in Feb. The solution above obviously does it for all lines.

Need help modifying awk statement above to include 'Feb' constraint.

Thanks,
Arun

Sun Jan 30 2011, 03:20 GMT 13:20 Local, Australia v England,Brisbane, 5th ODI
Mon Jan 31 2011, 09:00 GMT 14:30 Local, Sri Lanka v West Indies,Hambantota, 1st ODI
Sat Feb 5 2011, 22:00 GMT 11:00 Local, New Zealand v Pakistan,Auckland, 6th ODI
Sun Feb 6 2011, 09:00 GMT 14:30 Local, Sri Lanka v West Indies,Colombo (RPS), 3rd ODI
Sat Feb 12 2011, 04:00 GMT 09:30 Local, Kenya v West Indies,Colombo (RPS)
Sat Feb 12 2011, 04:00 GMT 09:30 Local, Sri Lanka v Netherlands,Pallekele
Tue Mar 1 2011, 09:00 GMT 14:30 Local, Sri Lanka v Kenya,Colombo (RPS), ICC Cricket World Cup
Wed Mar 2 2011, 09:00 GMT 14:30 Local, England v Ireland,Bangalore, ICC Cricket World Cup
Mon Apr 25 2011, NA GMT NA Local, West Indies v Pakistan,Gros Islet
Thu Apr 28 2011, NA GMT NA Local, West Indies v Pakistan,Bridgetown
Sun May 1 2011, NA GMT NA Local, West Indies v Pakistan,Bridgetown
Thu May 5 2011, NA GMT NA Local, West Indies v Pakistan,Providence
 
So: 4 fields and first field like *Feb*

[tt](NF==4) && ($1 ~ /Feb/)[/tt]

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top