|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Egrep pattern file
I created a file called test.txt and have the following line in it:
Code:
root@lore:~# cat test.txt hello Spider is a good man dont you know And with that i run the following command which returns the following: Code:
root@lore:~# egrep -io 'spider(.*)man' test.txt Spider is a good man But im wondering how to only return whats in the (.*) so it will only return in this example "is a good" Im just not sure how it saves that value of that. I wrote a php script to do this that uses an array but im wanting to run this just by typing a the whole command like how i have been trying in the command line. Anyone have any ideas? Last edited by krisrmgua : April 14th, 2008 at 09:57 PM. |
|
#2
|
|||
|
|||
|
Re: Egrep pattern file
Code:
root@lore:~# egrep -io 'spider(.*)man' test.txt Spider is a good man You can do this with the 'sed' command like this: Code:
sed -n 's/spider\(.*\)man/\1/pi' test.txt The -n suppresses output of every line, the \1 along with the p after the last slash makes it print the part of the expression in parenthesis(which need backslashes to be handled correctly). And the 'i' at the end makes it case insensitive. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > Linux Help > Egrep pattern file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|