Quick sed/awk question | Unix Linux Forums | Shell Programming and Scripting

  Go Back    

Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Quick sed/awk question

Shell Programming and Scripting

awk, question, sed

Closed Thread    
Thread Tools Search this Thread Display Modes
Old 12-10-2012
lucshi09 lucshi09 is offline
Registered User
Join Date: Jul 2012
Last Activity: 22 November 2013, 7:33 PM EST
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
Quick sed/awk question

Hi fellow linux-ers,

I have a quick question for you. I have the following text, which I would like to modify:

10 121E(121) 16 Jan
34S 132E 24 Feb
42 176E(176) 18 Sep
21S 164E 25 May
15 171W(-171) 09 Jul

How can I do the following 2 modifications using sed and/or awk?
1. in 1st column, if a field has an "S", delete the "S" and add a "-" in front of number
2. in the 2nd column, delete the parenthesis and the number that exists within it

Moderator's Comments:
code tags please
Sponsored Links
Old 12-10-2012
rdrtx1 rdrtx1 is offline
Registered User
Join Date: Sep 2012
Last Activity: 13 January 2015, 10:34 AM EST
Location: Houston, Texas, USA
Posts: 681
Thanks: 0
Thanked 206 Times in 198 Posts

awk '$1 ~ /S/ {gsub("S","",$1);$1="-"$1} {sub("[(].*[)]","",$2)} 1' infile

The Following User Says Thank You to rdrtx1 For This Useful Post:
lucshi09 (12-10-2012)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Quick Sed Question eo29 Shell Programming and Scripting 6 09-26-2011 09:28 AM
Quick Question on sed command in shell script luft Shell Programming and Scripting 4 09-10-2008 06:36 PM
Help with AWK -- quick question Probos Shell Programming and Scripting 5 07-18-2007 05:26 PM
quick sed question vbm Shell Programming and Scripting 2 11-09-2006 10:44 PM
a quick SED question hcclnoodles Shell Programming and Scripting 1 09-22-2006 11:54 AM

All times are GMT -4. The time now is 11:18 AM.