I have a file that prints out multiple occurrences of '200 OK'. I am only interested in the last occurrence of '200 OK' that comes after the pattern 'COMMAND'. In my particular file, "COMMAND" prints 100 time. It would look like this:
otherdata 200 OK otherdata 200 OK COMMAND 200 OK So I use the command.
grep -A1 COMMAND file | grep -v '200 OK' This give me the following output:
COMMAND xxxxx PASSWORD xxxxxx -- COMMAND xxxxx PASSWORD xxxxxx 513 unknown user account -- COMMAND xxxxxx PASSWORD xxxxxx -- COMMAND xxxxxx PASSWORD xxxxxx 513 unknown user account -- COMMAND xxxxxx PASSWORD xxxxxxx -- I am getting everything other than the 200 OK, but I do not need the lines that contain
COMMAND xxxxx PASSWORD xxxxx --- How can I get the output of only the lines with anything other than 200 OK and the line above it? Ideally, I want my output to include only lines like this and nothing else. The 513 is just an example there may be others.
COMMAND xxxxx PASSWORD xxxxxx 513 user account unknown