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


Tags
awk, question, sed

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
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:


Code:
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

Thanks!!!
Moderator's Comments:
code tags please
Sponsored Links
    #2  
Old 12-10-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 23 September 2014, 12:09 PM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 Posts
try:

Code:
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 08:28 AM
Quick Question on sed command in shell script luft Shell Programming and Scripting 4 09-10-2008 05:36 PM
Help with AWK -- quick question Probos Shell Programming and Scripting 5 07-18-2007 04:26 PM
quick sed question vbm Shell Programming and Scripting 2 11-09-2006 09:44 PM
a quick SED question hcclnoodles Shell Programming and Scripting 1 09-22-2006 10:54 AM



All times are GMT -4. The time now is 12:50 AM.