You're viewing a comment by Rama and its responses.

Rama Permalink
February 26, 2014, 23:44

Hi there Peter!
I just bought your Awk and Sed book and I think they are fantastic. I went through the entire Awk book and learnt a lot in a very short time. There is however a "specific" question which I was looking an answer for and did not find any. I was hoping you could give me some insight into the same.

I have a text file which has a single column of numbers which are not serially ordered (e.g, 1,4,6,9,11,27 and so on...) A few hundred of them (n=768). These are actually the line numbers of a very BIG file which has 50,000 lines of text.

What I would like to do is for either Awk or Sed to read the numbers in the text file and extract the full contents of each of the numbered line from the BIG file.

Is there a direct way to do this in either Awk or Sed? Or do I have to rely on a bash script to first read the text file, create and array and then load the array into a awk one liner one at a time and extract that particular line from the Big file?

A lot of the examples were either serial numbers i.e, lines 8 through 12 or something like that. None of the examples were random lines like the issue I am facing.

I would hugely grateful for any pointers here.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "security_257": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.