Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Quick sed/awk question

Shell Programming and Scripting


Tags
awk, question, sed

Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 12-10-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 25 June 2015, 6:26 PM EDT
Location: Houston, Texas, USA
Posts: 682
Thanks: 0
Thanked 206 Times in 198 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 08:48 AM.