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

Thanks!!!

try:

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