?
Solved

Need script to test text file

Posted on 2005-04-24
9
Medium Priority
?
327 Views
Last Modified: 2013-12-26
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
0
Comment
Question by:9thTee
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 13854264
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;
     }
}'
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 13854462
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;
}
0
 

Author Comment

by:9thTee
ID: 13855316
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?

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:9thTee
ID: 13855318
brettmjohnson:
I am not sure how to run your script.

Mark
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 13855453
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.

0
 
LVL 10

Accepted Solution

by:
Sys_Prog earned 2000 total points
ID: 13855530
case `head -1 textfile.txt | cut -c:60 -L:1` in
        "O")   qu
        ;;
        "d")    ak
        ;;
        "k")   pk
        ;;
        "a")    wt
        ;;
       *)      Other program
       ;;
esac



Amit
         
 
 
0
 

Author Comment

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

Thanks,
Mark
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 13855558
-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
0
 

Author Comment

by:9thTee
ID: 13855561
SysProg,
Well the script works fine without it on IBM AIX.  Thanks for the help.

Mark
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Integration Management Part 2
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question