I've a file with information like this
Info A: 1 Info B: 2 Info C: 3 Info D: 4 Info A: 1 Info B: 2 Info C: 123 Info D: 4
Now I'm trying to get the line with Info C but I need it separately. I need a command to get the output of Info C of the first block and a command to get the Info C from the second block. This command works for me, to get the Info C of both blocks. In the first part of the command, I'm deleting all the stuff except the lines with Info C. In the second part of the command, I'm deleting the string "Info C: "
cat test2 | sed -e '/Info C: /!d' -e 's/Info C: //'
The output contains only the value:
Now, to get it separately, I've tried several arguments for sed but nothing works for me.
The following solution works fine for me. I just print the first or the last line
cat test2 | sed -e '/Info C: /!d' -e 's/Info C: //' | sed -n '$p' cat test2 | sed -e '/Info C: /!d' -e 's/Info C: //' | sed -n '1p'
But I wonder, if there is a solution without a second pipeline for sed?