Find the answer to your Linux question:
Results 1 to 10 of 10
Hey guys, Does anyone knows linux/unix command to limit the number of lines from Displaying it. I tried man cat/grep no help on those. Any other commands where i could ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2004
    Posts
    42

    command to limit from displaying all


    Hey guys,

    Does anyone knows linux/unix command to limit the number of lines from Displaying it. I tried man cat/grep no help on those. Any other commands where i could limit from displaying it. I do not want to use less or more command. I want to use number to limit my displaying.

    Thanks in advance

    Suresh

  2. #2
    Linux User
    Join Date
    Jul 2004
    Location
    Poland
    Posts
    368
    Maybe "head" or "tail" are what you want....
    "I don't know what I'm running from
    And I don't know where I'm running to
    There's something deep and strange inside of me I see"

  3. #3
    Just Joined!
    Join Date
    Aug 2004
    Posts
    42
    Quote Originally Posted by kyku
    Maybe "head" or "tail" are what you want....
    Hey I want to only display it certain number of lines then exit from there. I writing shell script for that. But when i run this script, it wouldnt display the lines at all it it just staying there without doing anything.

    Is there is any other command that would i could limit the lines.

    #!/bin/bash

    PATTERN='Nov'
    location='/var/log/messages'
    output_filename='output.log'
    command_tail='tail -fn 50'

    linecount=$(grep $PATTERN $location|wc -l)
    write_to_file=$(cat $location|grep $PATTERN > /home/suresh/$output_filename)
    display_screen=$($command_tail $location)

    echo "$display_screen"
    echo "$linecount"

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer
    Join Date
    Jul 2003
    Location
    Farnborough, UK
    Posts
    1,305
    Would

    less --window=num

    be any good?

    Can't check it cos I'm at work at the moment.
    Lansbury's Lido

    thekiadriver on #linuxforums - fleetingly

  6. #5
    Just Joined!
    Join Date
    Aug 2004
    Posts
    42
    Quote Originally Posted by Chris H
    Would

    less --window=num

    be any good?

    Can't check it cos I'm at work at the moment.
    No go on that....does anyone has any shell scripts for this to limit the diaplying

  7. #6
    Linux User
    Join Date
    Jul 2004
    Location
    Poland
    Posts
    368
    Quote Originally Posted by suresheva31
    But when i run this script, it wouldnt display the lines at all it it just staying there without doing anything.
    That's the way -f flag for tail works - waits for more lines in input and displays them. I would remove it.
    "I don't know what I'm running from
    And I don't know where I'm running to
    There's something deep and strange inside of me I see"

  8. #7
    Just Joined!
    Join Date
    Aug 2004
    Posts
    42
    Quote Originally Posted by kyku
    Quote Originally Posted by suresheva31
    But when i run this script, it wouldnt display the lines at all it it just staying there without doing anything.
    That's the way -f flag for tail works - waits for more lines in input and displays them. I would remove it.
    I waited more than 10 mins no output at all...No man would wait 10 mins to produce a output. Rite?

    Any other aleternate solutions

  9. #8
    Linux User
    Join Date
    Jul 2004
    Location
    Poland
    Posts
    368
    Well, very strange... so strange that I tried it myself. Indeed when I tried your initial version it would hang infinitelly, obviously executing that "tail -fn 50". But as fast as I changed it to "tail -n 50" (note there's no -f as suggested in my previous post) it worked smoothly. It seems you're not a careful reader, Suresh.
    "I don't know what I'm running from
    And I don't know where I'm running to
    There's something deep and strange inside of me I see"

  10. #9
    Just Joined!
    Join Date
    Aug 2004
    Posts
    42
    Quote Originally Posted by kyku
    Well, very strange... so strange that I tried it myself. Indeed when I tried your initial version it would hang infinitelly, obviously executing that "tail -fn 50". But as fast as I changed it to "tail -n 50" (note there's no -f as suggested in my previous post) it worked smoothly. It seems you're not a careful reader, Suresh.
    Hey you got me on that...well it did work though, thank for you replies and evething. I really appreciate that but i did this way tooo

    The 10th to the 5th last line
    Code:
    echo '$-10,$-5 p' | ed -s file
    worked fine thanks

  11. #10
    Linux User
    Join Date
    Jul 2004
    Location
    Poland
    Posts
    368
    Never mind, thanks for making my 200th post
    "I don't know what I'm running from
    And I don't know where I'm running to
    There's something deep and strange inside of me I see"

Posting Permissions

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