LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-23-2007, 12:11 PM   #1
klinzter
LQ Newbie
 
Registered: Nov 2005
Posts: 8

Rep: Reputation: 0
Question Get somes lines from one file


Hello there,

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

file is bigger....



Best regards
 
Old 10-23-2007, 12:15 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Open the file and copy-paste?
 
Old 10-23-2007, 12:22 PM   #3
The_JinJ
Member
 
Registered: Apr 2004
Location: Scotland
Distribution: Suse, OpenWRT
Posts: 299

Rep: Reputation: 30
 
Old 10-23-2007, 12:24 PM   #4
klinzter
LQ Newbie
 
Registered: Nov 2005
Posts: 8

Original Poster
Rep: Reputation: 0
hummm, right, but i written script file, and i dont know to do :/
 
Old 10-23-2007, 12:26 PM   #5
klinzter
LQ Newbie
 
Registered: Nov 2005
Posts: 8

Original Poster
Rep: Reputation: 0
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
 
Old 10-23-2007, 12:26 PM   #6
The_JinJ
Member
 
Registered: Apr 2004
Location: Scotland
Distribution: Suse, OpenWRT
Posts: 299

Rep: Reputation: 30
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!!

Last edited by The_JinJ; 10-23-2007 at 12:46 PM.
 
Old 10-23-2007, 12:33 PM   #7
PMorph
Member
 
Registered: Sep 2003
Distribution: Debian
Posts: 213

Rep: Reputation: 31
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
 
Old 10-23-2007, 12:34 PM   #8
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Quote:
Originally Posted by klinzter View Post
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?
 
Old 10-23-2007, 12:50 PM   #9
indiancosmonaut
Member
 
Registered: Feb 2007
Posts: 65

Rep: Reputation: 15
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.
 
Old 10-23-2007, 03:36 PM   #10
klinzter
LQ Newbie
 
Registered: Nov 2005
Posts: 8

Original Poster
Rep: Reputation: 0
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
 
Old 10-23-2007, 06:00 PM   #11
klinzter
LQ Newbie
 
Registered: Nov 2005
Posts: 8

Original Poster
Rep: Reputation: 0
yes.....

works now....

after some experiences... its work

thks a lot
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Random file lines directed to a new file. In script an error. In command line no err leventis Programming 1 09-28-2006 08:16 AM
Last 10 lines of a large file loopoo Linux - Newbie 2 05-10-2006 04:01 AM
Replacing new lines (\n) from a file bkeeper Linux - Software 4 12-15-2005 03:13 AM
Removing lines from file Aylar Programming 2 04-22-2004 07:34 AM
somes strange problems : permission freenet Conectiva 5 07-13-2003 02:41 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration