Find the answer to your Linux question:
Results 1 to 3 of 3
Hi there I need some help with some instructions in command line I must create a script to recover some specific lines of text in a file, there are two ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    4

    help with command line

    Hi there

    I need some help with some instructions in command line

    I must create a script to recover some specific lines of text in a file, there are two files, one of them contain all the original data and the other indicates what lines of text I need from the original file.

    My question is: how can I get from my original file those specific lines of text based on my second file according to their line number?

    Here are some data of my files:

    Original file:
    1 0.0,0.009146,0.113636,0.0,0.153846,0.0,0.157407,0. 02,TRUE
    2 0.0,0.006098,0.0,0.007299,0.0,0.0,0.0,0.0,0.00885, TRUE
    3 0.027778,0.045732,0.0,0.043796,0.0,0.0,0.027778, FALSE
    4 0.009259,0.006098,0.0,0.00365,0.0,0.0,0.009259, TRUE
    5 0.027778,0.02439,0.004545,0.018248,0.076923, FALSE
    6 0.0,0.02439,0.0,0.029197,0.0,0.0,0.0,0.0, TRUE
    ...
    835 0.166667,0.097561,0.0,0.051095,0.0,0.0,0.166667, FALSE

    Second file:
    1 2:TRUE 1:FALSE + 1
    6 1:FALSE 2:TRUE + 1
    20 1:FALSE 2:TRUE + 1
    35 1:FALSE 2:TRUE + 0.978
    56 1:FALSE 2:TRUE + 1
    81 1:FALSE 2:TRUE + 0.999
    115 1:FALSE 2:TRUE + 1

    I need to get the lines 1,6,20,35,56,81,115... from my original file

    Your help will be highly appreciated

    Lu

  2. #2
    Just Joined!
    Join Date
    Oct 2008
    Posts
    4
    Hey I got it!
    Was very easy

    cut -c1-6 result_file.txt > second_file.txt
    while read myline
    do
    sed -n ${myline}p original_file.txt >>output.txt

    done < second_file.txt

  3. #3
    Just Joined!
    Join Date
    Aug 2007
    Posts
    25
    for i in `cat second_file | awk '{print $1}'`
    do
    grep ^$i orginal_file > output_file
    done

Posting Permissions

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