Connecting Tech Pros Worldwide Forums | Help | Site Map

new to unix

Newbie
 
Join Date: Nov 2006
Posts: 2
#1: Nov 8 '06
I'm having trouble with unix shell script. I need to "Cat every file (in D) whose name starts with ``test'' into a file (in D) called ``bigtest''". So far I have:
cat test*.txt > bigtest.txt But its not working the way it needs to. If someone could help me, I'd really appreciate it!

sicarie's Avatar
Moderator
 
Join Date: Nov 2006
Location: USA
Posts: 3,929
#2: Nov 8 '06

re: new to unix


Quote:

Originally Posted by ashmatusunrai

I'm having trouble with unix shell script. I need to "Cat every file (in D) whose name starts with ``test'' into a file (in D) called ``bigtest''". So far I have:
cat test*.txt > bigtest.txt But its not working the way it needs to. If someone could help me, I'd really appreciate it!

How is it working right now?
sicarie's Avatar
Moderator
 
Join Date: Nov 2006
Location: USA
Posts: 3,929
#3: Nov 9 '06

re: new to unix


Quote:

Originally Posted by sicarie

How is it working right now?

Right, that was a dumb question - do you have to use 'cat' or can you use another tool like ls or grep?

I suppose you might be able to cat the directory that those are in, but you'd still have to pass it to grep or something to handle the test*
Newbie
 
Join Date: Nov 2006
Posts: 3
#4: Nov 15 '06

re: new to unix


What you need is a FOR loop to get each of the files you need, cat each of them and APPEND ">>" to the target file (if you just write ">", each will overwrite the next):

> for i in `ls test*`
do
cat $i >> bigtest.txt
done
>
Reply


Similar Unix / Linux / BSD bytes