LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 05-27-2008, 02:06 AM   #1
Volcano
Member
 
Registered: Sep 2005
Posts: 172

Rep: Reputation: 15
can grep help me ?


i want to print lines from a file ABC.log .

lines which starts with words "2008-05-21" and ends with words "2008-05-21"

I want to print all lines in between .

How ?

whats the command ?

can grep help me ?

Last edited by Volcano; 05-27-2008 at 02:16 AM.
 
Old 05-27-2008, 04:29 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
You might use the address range feature of SED. For example:
sed -n '/patt1/,/patt2/p' filename
This prints lines, beginning with the one containing patt1, and ending with the one containing patt2.

Quote:
lines which starts with words "2008-05-21" and ends with words "2008-05-21"
This is ambiguous.....do you mean that each line starts and ends with those words? Or maybe you want a range of line beginning with the one containing pattern1 and ending with the one containing pattern2?

Note that the address range syntax may get confused when the beginning and ending patterns are the same.

For good tutorials on BASH in general: http://tldp.org
Excellent tutorials on many things, including SED and AWK: http://www.grymoire.com/Unix
 
Old 05-27-2008, 04:46 AM   #3
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
an 'awk' script would probably be the simplest solution - throw away lines until you get the one you want, then print lines until you get the last line you want

optionally you can play with the shell's assignment, looping, and pattern matching features

The only way to learn is to read the 'bash' manual and play around - have fun.
 
  


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
how to grep multiple filters with grep LinuxLover Linux - Enterprise 1 10-18-2007 07:12 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
grep: grep for two substrings? eur0dad Linux - General 2 08-17-2006 04:03 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM


All times are GMT -5. The time now is 02:37 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration