-   Programming (
-   -   unix shell script (

cxy0481 11-18-2005 12:28 PM

unix shell script
How do I cut fields from multiple files and redirect hem to a new file?

This is the script... the only problem I am having is getting the cut command to parse all of the files....

cd /no5odd/cidata
for i in imoddhs*.out
SM=`echo $i | sed -e "s/^imoddhs//" -e "s/.out$//"`
echo "$SM\\nRT_MISC\\nBR\\n/unixa/users/cyrtmisc$SM\\n" |odbe> /dev/null
cut -f1,6,10 cyrtmisc$SM > cynewrtmisc <<--this line does not work
lpr -s < /unixa/users/cynewrtmisc rop0
rm cynewrtmisc ; rm cyrtmisc*
exit 0

bulliver 11-18-2005 12:59 PM

I don't think anyone can help without knowing:

1. The format of your input files
2. the output you expect
3. the output you are actually getting

cxy0481 11-18-2005 01:08 PM

input files
Here is an example of one of the multiple input files - but I am not having a problem with the format - the "cut" utility is just giving me a cannot open error...

# pg cyrtmisc5
4ce TR303INT 672 0 0 5007 CKTNULL ENV_AUTO


Collecting data...
Compiling data... please be patient...
cut: cannot open cyrtmisc5 <<----------------------------
Report completed... printing to switch ROP /unixa/users/cynewrtmisc: cannot open
rm: cyrtmisc* non-existent

cxy0481 11-18-2005 01:26 PM

manual entry
If I enter the command at the prompt - does exactly what I want it to do...

#cut -f1,6,10 cyrtmisc$SM > cynewrtmisc

creates the "cynewrtmisc" file exactly the way I want it to... just won't work out of the script...

bulliver 11-18-2005 01:29 PM


echo "$SM\\nRT_MISC\\nBR\\n/unixa/users/cyrtmisc$SM\\n" |odbe> /dev/null
What is the point of this? You are just throwing the value away.
In any event your file cyrtmisc5 doesn't exist...

cxy0481 11-18-2005 02:06 PM

I got it.... thanks anyway...

eddiebaby1023 11-19-2005 04:50 PM



SM=`echo $i | sed -e "s/^imoddhs//" -e "s/.out$//"`

You can do this much more efficiently by using the shell's facilities, you know:


linmix 11-19-2005 04:56 PM

Since you asked for help, and got it (whether or not it did you any good doesn't really matter) maybe you could be solidary and share your sollution as well

(the only way to learn is by seeing as many sollutions as possible and I'm curious;))

eddiebaby1023 11-20-2005 09:04 AM


Originally posted by linmix
(the only way to learn is by seeing as many sollutions as possible and I'm curious;))
Nearly.:) The only way to learn is by seeing and understanding as many solutions as possible. Curiousity is always good, though.

linmix 11-20-2005 09:15 AM

You're right of course, so let's have it...

All times are GMT -5. The time now is 11:01 AM.