0

I am currently using the following to save terminal outputs to file:

$command -someoptions >> output.txt

However, I am only interested in one line from the terminal output. Is there a way to do this by changing the above expression. Or will I have to delete lines after the 'output.txt' file is formed?

For example: If my output is:

line 1
line 2
line 3
line 4
line 5

and all I want to save is:

line 4

where line 4 contains unknown information.

I am asking as I will later wish to script this command. Many thanks,

Solution Found:

I ended up using:

$command -someoptions | sed -n '4p' >> output.txt
Wychh
  • 656
  • 6
  • 20
  • You can pipe the output of your command into another command that will filter it, but you need to tell us what's the criterium for selecting `line 4`. Is it its position (4th line), or should we look for something special in that line? – Aaron Jan 17 '19 at 14:13

2 Answers2

1

This is a classic simple grep issue.

$command -someoptions | grep 'line 4' >> output.txt

You could refine that with more pattern complexity, and might need it depending on how precisely you need to match the data.

Paul Hodges
  • 13,382
  • 1
  • 17
  • 36
0

Try with this command:

$command -someoptions | grep " filter " >> output.txt

filter must be replaced by an element that distinguishes your line 4 from the other lines.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116