![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| script running with "ksh" dumping core but not with "sh" | simhe02 | HP-UX | 9 | 4 Weeks Ago 05:52 PM |
| #!/bin/sh script fails at StringA | tr "[x]" "[y]" | by_tg | UNIX for Dummies Questions & Answers | 3 | 02-22-2008 09:17 AM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-19-2007 10:52 PM |
| Avoid "++ requires lvalue" Error in Loop Calculation | sandeepb | Shell Programming and Scripting | 3 | 09-24-2007 04:02 AM |
| How to combine "find" command in for each loop (tcsh) | umen | Shell Programming and Scripting | 3 | 08-22-2005 01:07 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
ksh "while" loop within a csh script
I'm no unix pro for sure, but I have programmed enough other languages to usually get the job done in unix when I have to.
I'm currently trying to automate a manual diagnostic process. One of the steps in the manual process generates a file of text output. The next step is running a small script that adds the string " 0000" to the end of each line in the file, to prep it as input for a csh script. I thought it would be easy to combine the two scripts, but the script that adds the zeros is a ksh script with a "while" loop. Dropping that code into the csh script doesn't work. I have tried making the ksh snippet as csh-compliant as I know how, but I just don't know enough... Can you suggest how to duplicate this ksh functionality under csh? Here's the ksh code I have: #!/bin/ksh touch outfile cat infile | awk '{print $0}' | while read line do echo "$line 0000" >> outfile done Would there be any other considerations if "infile" and "outfile" were variables like $INFILE and $OUTFILE? I appreciate the help! |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Some suggestions...
touching the file is not really needed "cat file |" is a waste of a process. The next process can read from the file as easily as reading from a pipe. "| awk '{print $0}' |" is another expensive no-op echo >> outfile will open outfile for each line...just open the file once convert the csh script into ksh...ksh is the better shell or just invoke the csh script from inside of the ksh script #! /usr/bin/ksh exec < infile while read line ; do echo $line 0000 done > outfile /path/to/csh/script < outfile |
|
#3
|
|||
|
|||
|
Thanks for the advice! I was pretty sure that the ksh snippet was a kludge from someone who wasn't a pro either.
HOWEVER... I had a feeling that the popular answer would be to move everything into ksh. That's where I have a problem. The csh script is a bit lengthy, and it does tasks before and after the ksh piece. I think it'll be quicker for me to convert the little ksh snippet into csh instead of the other way around. Can you help out with that? Does csh have an equivalent to "while read"? I've tried the following: cat $INFILE | \ while (set INPUTLINE = $<) echo "$INPUTLINE 0000" >> $OUTFILE end But it gets hung up, as I think the "$<" part is waiting for input from the keyboard. What would happen if I split the csh file into two parts, and did this? #!/bin/ksh part1.csh [insert ksh 0000 snippet here] part2.csh |
|
#4
|
||||
|
||||
|
Sorry. I'm not a csh expert.
|
|
#5
|
||||
|
||||
|
To add the string " 0000" to the end of each line in the file...
Code:
awk '{print $0 " 0000"}' $INFILE > $OUTFILE
|
||||
| Google The UNIX and Linux Forums |