awk errors


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk errors
# 1  
Old 06-21-2005
awk errors

Hello,
Can you please let me know how to find all lines that don't begin with pattern1, pattern2, pattern3 and pattern4?
Here is my awk script that gives an error.

awk 'BEGIN { NAME="$FILE"
GSNO=0 }
/^ISA/ { FIRST=$0;
LAST="IEA*1*" + "substr($0,90,9}" }
/^GS/ { GSNO=++;
NAME="$FILE"$GSNO;
print "$FIRST" >> $NAME;
print $0 >> $NAME}
[/!^ISA/[,/!^GS/[,/!^GE/[,/!^IEA/]]]]{
print $0 >> $NAME
}

/^GE/ { print $0 >> $NAME;
print $LAST >> $NAME }
/^IEA/ {} ' $FILE

The red part should mean 'if it does not begins with ISA, GS, GE, IEA. I don't know the syntax.

Thanks.
# 2  
Old 06-21-2005
I'm having trouble reading your code, please use code tags.

Can you write a sentence that says what you are trying to do with the whole code block? Not just the part of pattern matching?
# 3  
Old 06-21-2005
OK, this is what I want.
There is a file like this:

ISAtext1
GStext2
text3
text4
...
textn
GE
IEA

I want to do this:

if line begins ISA - do command1.
if line begins GS -do command2.
all other lines (means all except ISA, GS, GE, IEA) - do command3. - how to write this in awk???
if line begins GE - do commad4
if line begins IEA -do command5.

Hope I was more clear.

Thanks
# 4  
Old 06-21-2005
I have fixed some of the syntax errors...

awk 'BEGIN { NAME="$FILE" <-- use -v to pass command line parameters
LAST="IEA*1*" + "substr($0,90,9}" } <-- use space for concatenation and don't surround functions by double quotes
/^GS/ { GSNO=++; <-- use either GSNO++ or GSNO+=1
NAME="$FILE"$GSNO; <-- there is no dollar sign when referring to variables
print "$FIRST" >> $NAME; <-- when writing to a new file just use > not >> (unless appending to an existing file)

Code:
awk -v FILE="NewFile" '
  BEGIN {
      NAME = FILE
      GSNO = 0
  }
  {
      if ($0 ~ /^ISA/) {
              FIRST = $0
              LAST = "IEA*1*" substr($0, 90, 9)
      } else if ($0 ~ /^GS/) {
              GSNO++
              NAME = FILE GSNO
              print FIRST > NAME
              print $0 > NAME
      } else if ($0 !~ /^(I[SE]A|G[SE])/) {
              print $0 > NAME
      } else if ($0 ~ /^GE/) {
              print $0 > NAME
              print LAST > NAME
      } else if ($0 ~ /^IEA/) {
              one = 1
      }
  } ' $FILE

# 5  
Old 06-22-2005
Thank you very much Igor.
It works! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] awk Errors on notation

can someone spot what i'm doing wrong here: awk 'BEGIN{printf("%0.2f", 1 / 2649320) * 100}' i get this error: awk: line 1: syntax error at or near * then i do this and get the answer i'm trying to avoid: awk 'BEGIN{print(1 / 2649320) * 100}' 3.77455e-05 (7 Replies)
Discussion started by: SkySmart
7 Replies

2. Shell Programming and Scripting

Solaris script using awk giving errors - please advise

I'm using solaris 10 Scenario as follows I have a logfile with 2 columns: column 1 = source directory + filename column 2 = destination directory + filename Using cron, my script polls for new files and adds them to the logfile ($ELOG) as described above. Using sed, the distination... (2 Replies)
Discussion started by: davidra
2 Replies

3. Programming

Errors in Perl when using awk command

Hi Guys, Hope everyone is fine :) I have this code below: #!/usr/bin/perl $num_of_files=`ls | grep -v remover | wc -l`; $remover=`ls -lrt | grep -v total | grep -v remover | head -1 | awk '{print $8}' | rm \`xargs\``; if ($num_of_files>3) { system ($remover); } When I... (3 Replies)
Discussion started by: rymnd_12345
3 Replies

4. UNIX for Dummies Questions & Answers

Major OS errors/Bash errors help!!!!

Hi all, dummy here.... I have major errors on entering the shell. On login I get: -bash: dircolors: command not found -bash: tr: command not found -bash: fgrep: command not found -bash: grep: command not found -bash: grep: command not found -bash: id: command not found -bash: [: =: unary... (12 Replies)
Discussion started by: wcmmlynn
12 Replies

5. Programming

errors....

hi i have written a program to display files in a directory but it doesnt compile on the sun/solaris system.... im using gcc(inbuilt compiler) im generally used to working on a windows environment so maybe im overlookiing something ive added comments to help readability of the program i also... (2 Replies)
Discussion started by: anything2
2 Replies

6. UNIX for Dummies Questions & Answers

X errors

I'm trying to set up x2x between my desktop and laptop, and as a precondition to that, I'm just trying to get each to be able to display programs on the other (e.g. "desktop$ xterm -display laptop:0"). OS is Ubuntu 5.10 and X version is X.org 6.8.2 I've set up X to run without -nolisten, and... (1 Reply)
Discussion started by: vertigo23
1 Replies

7. AIX

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (2 Replies)
Discussion started by: mcastill66
2 Replies

8. UNIX for Advanced & Expert Users

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (0 Replies)
Discussion started by: mcastill66
0 Replies

9. Shell Programming and Scripting

AWK Syntax errors :/

I recently started as an intern and my manager wanted to see how well I would handle Korn Bourne shell scripting without any prior experience, I have prior programming experience but I keep running into syntax errors with AWK. Please take a look at my simple code and tell me what stupid mistake... (6 Replies)
Discussion started by: yongho
6 Replies

10. Filesystems, Disks and Memory

Help with errors

I am very new to the world of Unix, in the middle of a crash course as I write this due to a system failure for my company. This system went down approximately 24 hours ago due to some apparent thunderstorms that passed through. The problem is that my company, like many others, has laid off... (5 Replies)
Discussion started by: Phaedirean
5 Replies
Login or Register to Ask a Question