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

P_sun Permalink
March 23, 2011, 18:32

Hi,
If I want to get the lines 506, 590 and 600 (from text1.log) written to out.log.
The following command allows me to do that:

awk 'NR==506||NR==590 || NR==600' "text1.log" > out.txt

Let us set a=506, b=590 and c=600.
Now what I need is lines 628 (a+(122)*n), 712 (b+(122)*n),
722 (c+(122)*n) ,where n=1-20 written out from text1.log.
Can awk be suitable for this?
Can someone outline how this can be done. I appreciate your help.

If the above needs to be repeated for a series of outputs, text2.log, text3.log, how can this be done? Any help is greatly appreciated.

Comment Responses

March 27, 2011, 04:08

Here is the code that should work for you:

for (( n=1; n<21; n++ )); do awk -v n=$n
'NR==a+(122*n)||NR==b+(122*n)||NR==c+(122*n)'
a=506 b=590 c=600 text1.log >>out.txt; done

This should be all in one line (a true "oneliner').

Reply To This Comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the first letter of your name: (just to make sure you're a human)

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