Sponsored Content
Full Discussion: Quick sed/awk question
Top Forums Shell Programming and Scripting Quick sed/awk question Post 302742173 by lucshi09 on Monday 10th of December 2012 04:50:53 PM
Old 12-10-2012
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:
Mod Comment code tags please
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

a quick SED question

I have a line EXTDIR=`echo $i | sed 's/\-tar.gz//'` which looks for files ending in -tar.gz, i would like to increase the functionality so that it looks for .tar.gz files as well as -tar.gz. Do i put the - in square brackets with a dot ? like this EXTDIR=`echo $i | sed 's/\tar.gz//'` ... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

2. Shell Programming and Scripting

quick sed question

hey, Im just wondering is there away to get sed to read from a variable eg it doesn't seem to work, i really need to be able to recursively change the same data set... (2 Replies)
Discussion started by: vbm
2 Replies

3. Shell Programming and Scripting

Sed or Awk Question

I have some text: 0400-0427 NA Czech Republic R. Prague 5990ca, 6200, 7345 0400-0456 NA, As Romania R. Romania Int'l 6115, 9515, 9690, 11895 0400-0500 NA U. S. A. WYFR 6065, 6855, 9505, 9715 0400-0500 NA,Eu,Af U. S. A. ... (8 Replies)
Discussion started by: petebear
8 Replies

4. Shell Programming and Scripting

Help with AWK -- quick question

Ok. I'm just starting to use AWK and I have a question. Here's what I'm trying to do: uname -n returns the following on my box: ftsdt-svsi20.si.sandbox.com I want to pipe this to an AWK statement and make it only print: svsi20 I tried: uname -n | awk '{ FS = "." ; print $1 }' ... (5 Replies)
Discussion started by: Probos
5 Replies

5. Shell Programming and Scripting

Quick Question on sed command in shell script

Hello, I have the following line in one of my shell scripts. It works fine when the search string($SERACH_STR) exists in the logfile($ALERTLOG) but if the search string does not exist this line errors out at run time. Is there a way to make this line return 0 if it is not able to find the... (4 Replies)
Discussion started by: luft
4 Replies

6. Shell Programming and Scripting

yet another sed/awk question

Unix Guru's , I have a file all_files.txt containing data as follows all_files.txt first file : /a/b/c/file.sh first second CLIENT1 second file : /a/b/c/file.sh first second CLIENT1 first file : /a/b/c/file.sh first second CLIENT2 second file : /a/b/c/file.sh first second... (6 Replies)
Discussion started by: jville
6 Replies

7. Shell Programming and Scripting

Quick Sed Question

Just want to know why when I do the following in sed, the required is not extracted. echo "ab01cde234" | sed 's/*$//' result: ab01cde (Which is correct) echo "ab01cde234" |sed 's/.*\(*\)$/\1/' result: blank (was expecting 234) or echo "ab01cde234" |sed 's/.*\(\)*$/\1/' result: blank... (6 Replies)
Discussion started by: eo29
6 Replies

8. Shell Programming and Scripting

awk Help: quick and easy question may be: How to use &&

Hi Guru's. I am trying to use to check if $5 is greater than 80 & if not 100, then to print $0 : awk '{ if ($5>80) && if ($5 != 100) print $0} But getting error: >bdf1|sed 's/%//g'|awk '{ if ($5>80) && if ($5 != 100) print $0}' syntax error The source line is 1. The error... (6 Replies)
Discussion started by: rveri
6 Replies

9. Shell Programming and Scripting

awk :quick question removing empty line.

How to write in awk to remove lines starting with "#" and then process the file: This is not working: cat file|awk '{if ($0 ~ /^#/) $0="";print NF>0}' When I just give cat file|awk '{if ($0 ~ /^#/) $0="";print }' it prints the blank lines . I don't wnat the blank lines along with the... (15 Replies)
Discussion started by: rveri
15 Replies

10. Shell Programming and Scripting

Quick awk question

gawk 'BEGIN{count=0} /^Jan 5 04:33/,0 && /fail/ && /09x83377/ { count++ } END { print count }' /var/log/syslog what is wrong with this code? i want to search the strings "fail" and "09x83377" from all entries. im grabbing all entries in the log starting from Jan 5 04:33 to the end of the... (3 Replies)
Discussion started by: SkySmart
3 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 10:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy