Sam Hakim Sam Hakim - 8 months ago 31
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!

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

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