LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   can grep help me ? (https://www.linuxquestions.org/questions/linux-newbie-8/can-grep-help-me-645009/)

Volcano 05-27-2008 02:06 AM

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 ?

pixellany 05-27-2008 04:29 AM

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

pinniped 05-27-2008 04:46 AM

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. :)


All times are GMT -5. The time now is 08:50 PM.