LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-18-2005, 12:28 PM   #1
cxy0481
LQ Newbie
 
Registered: Oct 2005
Posts: 11

Rep: Reputation: 0
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
do
SM=`echo $i | sed -e "s/^imoddhs//" -e "s/.out$//"`
echo "$SM\\nRT_MISC\\nBR\\n/unixa/users/cyrtmisc$SM\\n" |odbe> /dev/null
wait
done
cut -f1,6,10 cyrtmisc$SM > cynewrtmisc <<--this line does not work
wait
lpr -s < /unixa/users/cynewrtmisc rop0
rm cynewrtmisc ; rm cyrtmisc*
exit 0
 
Old 11-18-2005, 12:59 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 77
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
 
Old 11-18-2005, 01:08 PM   #3
cxy0481
LQ Newbie
 
Registered: Oct 2005
Posts: 11

Original Poster
Rep: Reputation: 0
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
4 XENAU FDRS CAC NAV 14 DBNO DBNO

OUTPUT:

# cyrt_misc.sh
Collecting data...
Compiling data... please be patient...
cut: cannot open cyrtmisc5 <<----------------------------
Report completed... printing to switch ROP
cyrt_misc.sh: /unixa/users/cynewrtmisc: cannot open
rm: cyrtmisc* non-existent
 
Old 11-18-2005, 01:26 PM   #4
cxy0481
LQ Newbie
 
Registered: Oct 2005
Posts: 11

Original Poster
Rep: Reputation: 0
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...
 
Old 11-18-2005, 01:29 PM   #5
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 77
Quote:
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...
 
Old 11-18-2005, 02:06 PM   #6
cxy0481
LQ Newbie
 
Registered: Oct 2005
Posts: 11

Original Poster
Rep: Reputation: 0
I got it.... thanks anyway...
 
Old 11-19-2005, 04:50 PM   #7
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Quote:
Code:
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:
Code:
SM=${i#imoddhs}
SM=${SM%.out}
 
Old 11-19-2005, 04:56 PM   #8
linmix
Senior Member
 
Registered: Jun 2004
Location: Spain
Distribution: FC5
Posts: 1,993
Blog Entries: 1

Rep: Reputation: 46
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)
 
Old 11-20-2005, 09:04 AM   #9
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Quote:
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.
 
Old 11-20-2005, 09:15 AM   #10
linmix
Senior Member
 
Registered: Jun 2004
Location: Spain
Distribution: FC5
Posts: 1,993
Blog Entries: 1

Rep: Reputation: 46
You're right of course, so let's have it...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unix shell script:How to delete the first line in a file?? rche3252 Programming 6 03-03-2010 08:32 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM
telnet windows m/c from unix shell script ann124 Programming 1 11-10-2004 02:26 PM
unix korn shell script that interact with windows java program ann124 Programming 5 11-09-2004 10:14 PM
How to schedule unix script periodically from unix os level??? gopi_20us Programming 2 03-11-2002 07:45 AM


All times are GMT -5. The time now is 04:14 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration