LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 11:11 AM   #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, 11:15 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

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

Rep: Reputation: 30
 
Old 10-23-2007, 11:24 AM   #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, 11:26 AM   #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, 11:26 AM   #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 11:46 AM.
 
Old 10-23-2007, 11:33 AM   #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, 11:34 AM   #8
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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, 11:50 AM   #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, 02: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, 05: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



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 07:16 AM
Last 10 lines of a large file loopoo Linux - Newbie 2 05-10-2006 03:01 AM
Replacing new lines (\n) from a file bkeeper Linux - Software 4 12-15-2005 02:13 AM
Removing lines from file Aylar Programming 2 04-22-2004 06:34 AM
somes strange problems : permission freenet Conectiva 5 07-13-2003 01:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:07 PM.

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
Open Source Consulting | Domain Registration