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 
1
  • 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? Commented Jan 17, 2019 at 14:13

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.