简体   繁体   中英

Search a pattern with spaces in unix text file

I've a pattern line (like below) in unix text file.

Now I want to search those lines in a file and my search criteria will be Mar 31 2015. Can I achieve this with grep.

Because my search criteria is not that simple.

Regards,

DKamran

Use .* in the regular expression to match anything between the date and year.

grep "Mar 31.*2015" filename

To search for is intelligent , do:

grep "is .* intelligent" filename

You could try the below grep command.

grep '\bMar 31 [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\} 2015\b' file

\\{2\\} quantifier repeats the previous token [0-9] exactly two times.

This will work with any time in the specified format in between, but not with other characters.

/Mar\s31\s[\d:]+\s2015/

You can test it here . It will print out the matching lines along with the line-number if used with grep -nP .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM