Link to home
Start Free TrialLog in
Avatar of 9thTee
9thTee

asked on

Need script to test text file

Hi,
I need a script to test a text file and based on the character it finds on line 1 column 60, run different programs.  The script can be awk, perl or whatever else that will run on IBM AIX.
 
If line 1 column 60 is "O" then run program qu
If line 1 column 60 is "d" then run program ak
if line 1 column 60 is "k" then run program pk
If line 1 column 60 is "a" then run program wt
If line 1 column 60 is anything else, run program other

Any help would be appreciated.

Thanks,
Mark
Avatar of Peter Kwan
Peter Kwan
Flag of Hong Kong image

awk < textfile.txt 'NR == 1 {
     switch (substr($0, 60, 1)) {
     case "O": qu; break;
     case "d": ak; break;
     case "k": pk; break;
     case "a": wt; break;
     default: other;
     }
}'
switch (`head -1 textfile.txt | cut -c 60-60`)
case "O": qu; break;
case "d": ak; break;
case "k": pk; break;
case "a": wt; break;
default: other;
}
Avatar of 9thTee
9thTee

ASKER

pkwan:

When I run this it says:

 Syntax Error The source line is 2.
 The error context is
                switch >>>  (` <<< 
 awk: 0602-502 The statement cannot be correctly parsed. The source line is 2.
 Syntax Error The source line is 3.


Any ideas?

Avatar of 9thTee

ASKER

brettmjohnson:
I am not sure how to run your script.

Mark
nevermind, brain burp on my part.  The only interesting part is

`head -1 textfile.txt | cut -c 60-60`

which returns the specific character of interest.
The switch statement is from the previous post
and is in awk/C syntax, not Bourne shell syntax.

ASKER CERTIFIED SOLUTION
Avatar of Sys_Prog
Sys_Prog
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 9thTee

ASKER

Hi SysProg,
What does the L:1 do?  I had to remove it for the script to run.

Thanks,
Mark
-L means how many characters to consider
By default, it takes upto the end of line
-c means the start position from where u want to cut the string


Amit
Avatar of 9thTee

ASKER

SysProg,
Well the script works fine without it on IBM AIX.  Thanks for the help.

Mark