Thread: using cat to putput data and save

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    118

    using cat to putput data and save

    i need to make a command with pipes where i sort a file and display the top 8 lines in the file then output it and saves the output

    i have this so far
    Code:
    sort -k 3,5 /home/brian.perry/uli101/data.txt | head -n 8 | cat > output.txt
    the bold part is where im guessing the problem is, it saves the output into output.txt but i dont see the output which is also what i need it to do.

    Any suggestions?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    sort -k 3,5 /home/brian.perry/uli101/data.txt | head -n 8 > output.txt
    Just remove the "| cat" part.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    118
    ya, i would but i need three commands using two pipes. For the last command i need to output and save the output i searched many times on google.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Actually, you have three commands and two pipes in what I posted, but here's one with another command and another pipe, if you prefer that:

    Code:
    cat /home/brian.perry/uli101/data.txt | sort -k 3,5 | head -n 8 | cat > output.txt
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    118
    http://img259.imageshack.us/img259/488/boxni5.png

    For the assignment it should look like this cammand1 | command2 | command3.

    thats what i meant sorry if i didnt make sense

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    What do you actually want? That you get the output both to the console and to a file? You can use tee for that.

    Code:
    sort -k 3,5 /home/brian.perry/uli101/data.txt | head -n 8 | tee output.txt
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    118
    Thanks alot man that worked.

  8. #8
    Registered User t3chn0n3rd's Avatar
    Join Date
    Dec 2007
    Location
    kansas city
    Posts
    25

    nice coding

    elegant code

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    useless post - despite the compliment
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. save data held in memory into the file
    By amy1234 in forum C Programming
    Replies: 3
    Last Post: 11-04-2008, 06:36 PM
  2. Does realloc save the previous buffer data?
    By Niara in forum C Programming
    Replies: 6
    Last Post: 07-23-2008, 04:40 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. How To Save Dynamic Data
    By GaPe in forum C Programming
    Replies: 1
    Last Post: 11-25-2003, 10:41 AM