bash: reading a particular line
Hi,
I am trying to write a script which takes another file and reads in a particular line of the file. Could somebody please point me in the correct direction as to how i would go about reading the i-th line from the text file please? Many thanks, Seb |
There is more then one solution to this problem, here's one using sed:
THISLINE=12 sed -n "${THISLINE}p" <filename> This will print line number 12. Ranges are also possible: FIRSTLINE=12 LASTLINE=17 sed -n "${FIRSTLINE},${LASTLINE}p" <filename> Like I said, this is just one way of doing it. Hope this helps. |
Here's another using the head and tail commands:
Code:
line_number=12 |
All times are GMT -5. The time now is 01:40 PM. |