Results 1 to 2 of 2

Thread: Using the grep command to find lines

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Using the grep command to find lines

    Hi

    I have used the grep function to display all the lines of a file that displays a particular word, Now i want to display all the lines that display a list of numbers.

    For this data set. grip 11837054|60497718|46891756| file .This will read all the lines congaing these numbers. However if i have 5000 numbers i would like to display lines for i would have to individually type in 5000 number combinations. Is there any quicker way of doing this?

    MemberID ClaimsTruncated DaysInHospital AgeAtFirstClaim Sex
    11837054 0 0 70-79 M
    60497718 1 1 70-79 M
    46891756 0 1 70-79 M
    31394988 0 0 40-49 M
    69389881 0 0 0-9 M
    276553 0 0 40-49 F
    41304691 0 0 30-39 M
    29061798 0 0 70-79 F
    67052973 0 0 40-49
    19834466 0 0 0-9 M

  2. #2
    Is that all you got? rockdalinux's Avatar
    Join Date
    May 2005
    Location
    Planet Vegeta
    Posts
    987
    Thanks
    27
    Thanked 71 Times in 62 Posts
    Rep Power
    19

    Default

    I'm assuming that the sample table provided is stored in a text file. If so it is quite easy. Read the file, get first column (field), and give it to grep. However, grep will not accept 5000 argument on line due to command line arg. You can feed number one by one as you read from the file.

    Code:
    while IFS= read -r line
    do 
      awk '{ print $1}'  | xargs -I {} grep  "{}" file
    done < "input_file.txt"
    Rocky Jr.
    What's wrong? I hope I am not making you uncomfortable...

    Never send a boy to do a mans job.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Grep command count number of CPU
    By sidebrake in forum Shell scripting
    Replies: 6
    Last Post: 12th August 2013, 01:09 PM
  2. Find command
    By Wingnut in forum KDE
    Replies: 2
    Last Post: 18th February 2010, 03:31 PM
  3. [Solved] Grep and sed command to print files
    By kenshin88 in forum Shell scripting
    Replies: 6
    Last Post: 16th December 2009, 04:23 PM
  4. [Solved] Comment out lines in .htaccess using sed command
    By cosminnci in forum Shell scripting
    Replies: 2
    Last Post: 4th July 2009, 01:16 AM
  5. Replies: 1
    Last Post: 16th March 2009, 07:46 PM

Tags for this Thread

Posting Permissions

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