Results 1 to 4 of 4

Thread: giving input to cat command from ls output

  1. #1
    Join Date
    Aug 2012
    Beans
    539

    giving input to cat command from ls output

    Hi,
    I am new to shell scripting.

    I want to basically use cat command as,
    cat file1.txt file2.txt > output.txt

    But the inputs namely file1.txt and file2.txt should come from the ls output as ls fil*.txt.
    I know I have to use pipes(|) but I'm finding it difficult to google.

    Please advise.
    Thanks.

  2. #2
    Join Date
    Aug 2012
    Beans
    539

    Re: giving input to cat command from ls output

    Right, got it done. I used this script.

    Code:
    #!/bin/bash
    
    
    for file in fil*.txt
    do
      cat "$file"
      echo
    done > newfile
    Thanks.
    Unable to mark thread as solved.

  3. #3

    Re: giving input to cat command from ls output

    you didn't try this?
    Code:
    cat fil*.txt >newfile

  4. #4
    Join Date
    Aug 2012
    Beans
    539

    Re: giving input to cat command from ls output

    Quote Originally Posted by trent.josephsen View Post
    you didn't try this?
    trent.josephsen, I don't know what I was thinking.
    I have been up for some time and was just not thinking right, I guess.

    Thanks anyways.
    Feel so stupid

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •