LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Get somes lines from one file (https://www.linuxquestions.org/questions/linux-newbie-8/get-somes-lines-from-one-file-593938/)

klinzter 10-23-2007 11:11 AM

Get somes lines from one file
 
Hello there,

i need help, how can get some lines between 2 words?

file is bigger....



Best regards

matthewg42 10-23-2007 11:15 AM

Open the file and copy-paste?

The_JinJ 10-23-2007 11:22 AM

:confused:

klinzter 10-23-2007 11:24 AM

hummm, right, but i written script file, and i dont know to do :/

klinzter 10-23-2007 11:26 AM

like....

perl -ne 'print if my_first_line .. my_second_line' big_file.txt > export.txt

ex:

perl -ne 'print if 1203 .. 3929' big_file.txt > export.txt

so, i want use 2 words

thks in advance

The_JinJ 10-23-2007 11:26 AM

perl -e 'print "Like";' -e 'print " This?"' > test.txt

Don't think you can use the -n loop to do this - or have i misunderstood?

Using -n would be like
perl -n -e 'code' somefile

Interpreted as

while (<>) {
# code
}

Tested this and it works
perl -n -e '!EOF' test.sh test2.sh > othertest.sh

EDIT Think I misunderstood what he's trying to do!!

PMorph 10-23-2007 11:33 AM

grep -A 100 start file | grep -B 100 end | grep -v start | grep -v end

Where "file" is the target file name, "start" is the opening word, "end" is the closing word, 100 is maximum nuber of lines between "start" and "end".
Extremely terrible, but maybe it encourages someone to post something more sophisticated :D

matthewg42 10-23-2007 11:34 AM

Quote:

Originally Posted by klinzter (Post 2933840)
hummm, right, but i written script file, and i dont know to do :/

What do you have so far?

What criteria do you want to use to decide which parts of the file to select?

indiancosmonaut 10-23-2007 11:50 AM

you can use

sed -n '/FIRST_WORD/,/SECOND_WORD/p' big_file >reqd_file

note: This will also contain the lines containing the FIRST_WORD and the SECOND_WORD.

klinzter 10-23-2007 02:36 PM

Matthew,

for ex:

today, my "key" are in the line 244

tomorrow, my same "key" can be 230 or the other line




Best Regards,


ps. sorry about my english :(

klinzter 10-23-2007 05:00 PM

yes.....

works now.... :)

after some experiences... its work ;)

thks a lot


All times are GMT -5. The time now is 05:36 AM.