Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-10-2012
Registered User
 
Join Date: Jul 2012
Posts: 8
Thanks: 1
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
Registered User
 
Join Date: Sep 2012
Location: Houston, Texas, USA
Posts: 571
Thanks: 0
Thanked 174 Times in 168 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

Tags
awk, question, sed

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 04:57 AM.