Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting n-th line of text output

Tags:

linux

I have a script that generates two lines as output each time. I'm really just interested in the second line. Moreover I'm only interested in the text that appears between a pair of #'s on the second line. Additionally, between the hashes, another delimiter is used: ^A. It would be great if I can also break apart each part of text that is ^A-delimited (Note that ^A is SOH special character and can be typed by using Ctrl-A)

like image 445
syker Avatar asked Apr 08 '10 17:04

syker


People also ask

How do I print the nth line in bash?

N is the line number that you want. For example, tail -n+7 input. txt | head -1 will print the 7th line of the file. tail -n+N will print everything starting from line N , and head -1 will make it stop after one line.

How do you print the nth line in Unix?

M~N with “p” command prints every Nth line starting from line M. For example, 3~2p prints every 2nd line starting from 3rd line as shown below.


2 Answers

output | sed -n '1p'  #prints the 1st line of output  output | sed -n '1,3p'  #prints the 1st, 2nd and 3rd line of output 
like image 178
N 1.1 Avatar answered Sep 23 '22 19:09

N 1.1


your.program | tail +2 | cut -d# -f2  

should get you 2/3 of the way.

like image 20
Grumdrig Avatar answered Sep 25 '22 19:09

Grumdrig