Results 1 to 5 of 5
hello all..
Could anyone help me on this stuff ?
i have a directory with a bounch of files.. every file has a lot of text and i need to ...
- 08-01-2007 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 2
find string in a list of files
hello all..
Could anyone help me on this stuff ?
i have a directory with a bounch of files.. every file has a lot of text and i need to grab a part like this. customName: sdfasdfff@country
example:
line 1 bla la bla bla bla
bla la bla bla bla
customName: sdfasdfff@country fasdf
bla la bla bla bla
bla la bla bla bla
-- END OF FILE --
wich is the best way to do this?
thanks in advance,
Bruno
- 08-01-2007 #2Just Joined!
- Join Date
- Jul 2007
- Posts
- 3
sed -n -e '/^customName: sdfasdfff@country fasdf$/p' *
or maybe
grep -h "^customName: sdfasdfff@country fasdf$" *
- 08-01-2007 #3Just Joined!
- Join Date
- Aug 2007
- Posts
- 2
thanks that work.
i only have one more little question if you don't mind.
I dont have much expertise on regex so could you point me on how to grab only the text after customName til end of line
for instance:
text sample: customName: sdfasdfff@country fasdf
grep -h "^customName: [grabStuff *.* ] $" *
i only need this return sdfasdfff@country
best regards,
and thank so much for your help.
really appreciated.
Bruno
- 08-01-2007 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try cut, the delimiter is a space and print the second field.
Check the man page.
Regards
- 08-01-2007 #5Just Joined!
- Join Date
- Jul 2007
- Posts
- 3
I'm not sure what you want from your last message.
Given target lines of
customName: sdfasdfff@country fasdf
If you only want the address (neither "customName: " nor " fasdf")
sed -n -e 's/^customName: *\(.*@.*\) *.*$/\1/p' *
Note there are exactly 2 spaces then the * in BOTH cases above.
If you want sdfasdfff@country fasdf
sed -n -e 's/^customName: *//p' *
Note there are exactly 2 spaces before the *
If you want to have some fun, there are (at least) 2 solutions using awk:
awk '/^customName: / { print $2, $3 }' *
awk '/^customName: / { print $2 }' *
The comma in the first awk (after $2) gives you a space between fields.
print $2 $3 will jam the fields together, which you do not want.
Note the final * in all the examples is the list of files you wish to scan.
sed is generally much faster than awk. The best book I've ever read (several times over the years) is the O'Reilly book, "sed & awk" by Dale Dougherty and Arnold Robbins.
O'Reilly Media -- Bookstore: sed & awk, Second Edition


Reply With Quote