Consider that after grep, awk and grep again I have a list of line numbers looking like this:


The command I'm using looks like this:

grep '01/01' /var/log/some.log | grep 'some' | awk '{print $10}' | grep -vn 200 | awk -F ':' '{print $1}'

I would like to now print those lines from that file, ideally by continue to pipe this command. Any ideas?

I know I could simply remove awk '{print $10}'and awk -F ':' '{print $1}' but for some reason when I do this I get no results, whereas when I try with the command posted above I do get the list of numbers.

  • Please provide sample input file contents and desired output: it might be better to rewrite the entire chain of commands.
    – simlev
    Apr 18, 2018 at 9:25
  • when I do this I get no results: there must be a 200 somewhere else on all the lines that contain both 01/01 and some, so your grep -vn 200 filters out all of them and not just those that have 200 in the 10th field.
    – simlev
    Apr 18, 2018 at 9:40

1 Answer 1



| xargs -I{} sed '{}q;d' /var/log/some.log

See How to get n-th line from a file


You could probably shorten your long sequence of pipes (including the above last step) by writing a more elaborate sed, awk or perl command:

perl -lane 'print $F[9] if /01\/01/ and /some/ and $F[9]!~/200/' /var/log/some.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.