Find the answer to your Linux question:
Results 1 to 6 of 6
I want to process the individual line of a very huge file (674 lines) .. using tail +line no|head -1 is very time consuming.. how can i extract every individual ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2005
    Posts
    24

    Extracting each line in a file


    I want to process the individual line of a very huge file (674 lines) .. using tail +line no|head -1 is very time consuming.. how can i extract every individual line of this file for processing.. some alternate option ..

  2. #2
    Just Joined!
    Join Date
    Oct 2005
    Location
    Mass
    Posts
    52

  3. #3
    Just Joined!
    Join Date
    Nov 2005
    Location
    Chicago, IL
    Posts
    46
    i=1
    while [ i -le 674 ]
    sed -n $[$i]p
    filename > if an output...filename here
    You can cat to read the response here....
    ...whatever other actions you need to do

    ((i++))
    done
    It is called making a loop and one of the MOST POWERFUL Shell Scripting tools is sed. Learn it real well. Let me ask you a question....with the amount of questions that your asking and the time of questions....does this relate to school work or is it something you are attempting to pick up on your own...because from what I remember of you other posts.....you are using Redhat. Pick up a book on Redhat and you can find all these answers that you are looking for.

    As I read dafl00 response....either way you do it....it will work for you. There is NEVER one way to reach a result.

  4. #4
    Linux Engineer
    Join Date
    Mar 2005
    Posts
    1,431
    Another possibility is something like this:
    Code:
    cat file|xargs <blah>
    Replace <blah> with a command which processes the content, then it'll execute the command on every single line in the file.

  5. #5
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Yet another way:
    Code:
    awk '&#123; do something; &#125;' some-file
    Depends a bit on what you're actually trying to do to each line of that file..

  6. #6
    Linux User
    Join Date
    Jul 2004
    Location
    Poland
    Posts
    368
    How about:

    Code:
    i=1
    while read
    do
      echo $i $REPLY
      &#40;&#40;i++&#41;&#41;
    done < /tmp/the_file.txt
    The trick is that 'read' built-in function, when given no parameters, stores the entire line read in $REPLY variable, which can then be processed.

    Hope this is the winner
    "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
  •