Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ksh and Perl

Status
Not open for further replies.

tbohon

Programmer
Apr 20, 2000
293
US
Need to pass an argument from a ksh script to a Perl script. Why? I need to filter out four fields from a multi-field file so the user isn't overly confused and I can't figure out how to do it in the shell without dropping into Perl. FYI, file is pipe-delimited with 12 fields ([0] thru [11]).

If there's a way to do this kind of thing in .ksh I'm unable to find any reference to it as that would obviously be preferable.

If this has to be done in Perl, how do I call a Perl script from the .ksh script and pass the value I need to pass?

Thanks again in advance.

Tom
 
Because I'm hoping there's a ksh way to do it ... and, since the Perl program is being called from a ksh script, it seemed appropriate to post here.

"My mind is like a steel whatchamacallit ...
 
In ksh, to pass arguments to command you simply do this:
command arg1 arg2 ... argN
You have to know how a Perl script retrieve the positional parameters.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
In Awk, the first field is $1.
[tt]
echo $foo |awk 'BEGIN{FS=OFS="|"}{print $1,$2,$3,$4}'
[/tt]
If you want to print the whole file:
[tt]
awk 'BEGIN{FS=OFS="|"}{print $1,$2,$3,$4}' thefile
[/tt]
 
take a look to awk oe nawk or gawk (almost the same, but the base is awk)

man awk

And post an example.

Cheers.
 
Haven't ever used awk but it's certainly worth a try ... will give it a shot in the morning and post results here.

Thanks all!!!

"My mind is like a steel whatchamacallit ...
 
Tried it - works just great!

Here is the line of code I used:

Code:
awk 'BEGIN{FS=OFS="|"}{print $3, $6, $7, $12 "\n"}' adt${1}.error > adt${1}.ready

Thanks to all for the help ... and for allowing me to learn from you.

Happy Holidays!

Tom

"My mind is like a steel whatchamacallit ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top