new to unix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashmatusunrai
    New Member
    • Nov 2006
    • 2

    new to unix

    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
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    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?

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      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*

      Comment

      • rdettwyler
        New Member
        • Nov 2006
        • 3

        #4
        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
        >

        Comment

        Working...