Sam Hakim Sam Hakim - 1 year ago 86
Bash Question

Match pattern in line using grep

I need to grep lines from a file with comma separated values, and direct the output to another file. Thus, if the second value starts with 'U' and the last value is 'Success', then this line matches the pattern.

Should match the pattern:


Should fail to match:


Thank you!

Answer Source
grep '^[^,]*,U.*,Success$'

Look for the first comma, a U, the last comma, Success and end of line.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download