|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
grep two strings in a file..
Hello All,
I have a big file about 1000 lines. Now i am trying to grep a particular string and printing the lines from the string. say for example in 500th line i have the date as "Mon Wed 14 20:15:24 2010". now i in my case i need to grep the combination of the strings "Mon Wed 14" and the other string "2010". i need to ignore the time among the whole string. so in one command i need to grep the two strings and ignore the time alone. Please help in this regard. Thanks in advance. Raju |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Code:
sed -n -e '/Mon Wed 14 [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\} 2010/p' file1cheers, Devaraj Takhellambam |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
You can use the grep command as follows Code:
grep "Mon Wed 14.*2010" filename So this will match the combination of the strings Mon Wed 15 and 2010 from that lines. Last edited by Scott; 02-23-2010 at 07:16 AM.. Reason: Added code tags |
|
#4
|
||||
|
||||
|
Try: Code:
grep 'Mon Wed 14 [0-2][0-9]:[0-5][0-9]:[0-5][0-9] 2010' file |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
try
cat file | grep "Mon Wed 14 20" | grep "2010" |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Few points:
1. Useless use of cat. No need of cat there 2. It fail for conditions such as Mon Wed 14 20 12:10:10 2009 djflsdjfjdsjjf2010 |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Date Matching:
You can use the following command,which will work for any kind of date. Code:
egrep "[A-Z][a-z]{2} [A-Z][a-z]{2} [0-9]{2} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [0-9]{0,4}" fileLast edited by Scott; 02-23-2010 at 07:15 AM.. Reason: Please use code tags |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep a string in the lines between 2 strings of a file | bhagirathi | Shell Programming and Scripting | 8 | 07-10-2009 04:47 AM |
| Grep Multiple Strings | durgaprasad | Shell Programming and Scripting | 10 | 06-26-2009 06:38 AM |
| grep strings of a certain length | angela.perez7 | Shell Programming and Scripting | 2 | 02-14-2009 02:39 PM |
| Grep strings from file and put in Column | thepurple | Shell Programming and Scripting | 2 | 12-08-2008 02:50 AM |
| want to grep only strings in a file? | balan_mca | Shell Programming and Scripting | 5 | 11-03-2008 05:19 AM |
|
|