Wrathchild
Technical User
greetings, I'm very green to sed & awk and am working on a project to read each line in a file and if it contains "START" or "END" then I want to capture those lines plus anything in between them. This is a log file so I'm looking to get the beginning and end of a transaction. Also I only want certain users' records, in this case USERID001 & USERID002.
If I understand correctly, sed is used for reading whole lines whereas awk is more for columns or fields. So I was thinking sed would be more applicable for this instance, but I'm not really sure.
Sample log file:
"Blah blah START blah USERID001"
"Blah blah blah"
"Blah blah blah"
"Blah END"
"this line shouldn't be included"
"Blah START USERID003"
"Blah"
"Blah END"
"Blah START USERID002"
"Blah"
"Blah END"
New file should read:
"Blah blah START blah USERID001"
"Blah blah blah"
"Blah blah blah"
"Blah END"
"Blah START USERID002"
"Blah"
"Blah END"
I've tried various things with sed & awk but most of the examples I see are for replacing text or parsing out just the pattern matched on.
thanks for the help as always
If I understand correctly, sed is used for reading whole lines whereas awk is more for columns or fields. So I was thinking sed would be more applicable for this instance, but I'm not really sure.
Sample log file:
"Blah blah START blah USERID001"
"Blah blah blah"
"Blah blah blah"
"Blah END"
"this line shouldn't be included"
"Blah START USERID003"
"Blah"
"Blah END"
"Blah START USERID002"
"Blah"
"Blah END"
New file should read:
"Blah blah START blah USERID001"
"Blah blah blah"
"Blah blah blah"
"Blah END"
"Blah START USERID002"
"Blah"
"Blah END"
I've tried various things with sed & awk but most of the examples I see are for replacing text or parsing out just the pattern matched on.
thanks for the help as always