Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading a particular line from a file in bash script using variable as line number

Tags:

bash

shell

sed

I have a csv file which contains a large number of entries. I have to read certain lines from the file. The line number is stored in a variable called lineno.
How to accomplish this?It may look something like:

line=$(sed -n "($lineno)p")

I want to know the correct syntax to do this.
Thanks

like image 468
nishantsingh Avatar asked Feb 08 '14 20:02

nishantsingh


1 Answers

You pretty much have it.

line=$(sed -n "${lineno}p" "$file")
like image 151
kojiro Avatar answered Oct 20 '22 06:10

kojiro