System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Awk expert's help needed (how to edit a text file?)

 
SOLVED
Go to solution
Occasional Advisor

Re: Awk expert's help needed (how to edit a text file?)

I forgot to mention:

in line 18 and after, only add the phrase (" /work/" to the beginning of the line if the line contains the phrase "htm".

Honored Contributor

Re: Awk expert's help needed (how to edit a text file?)

VERY SIMPLE using ex:

ex file <1,17d f
g/htm/s/^/work/
0pu f
wq
EOS

live free or die
harry d brown jr



Live Free or Die
Occasional Advisor

Re: Awk expert's help needed (how to edit a text file?)

Do you think I can do it with AWK?

I don't have a choice.
Honored Contributor

Re: Awk expert's help needed (how to edit a text file?)

awk '/htm/{if (NR >= 18) { print "/work/" $0} else { print $0}}' yourfile >resultfile

HTH

-- Rod Hills

PS - even small points to previous posts is a way to acknowledge the effort by the poster.
There be dragons...
Honored Contributor

Re: Awk expert's help needed (how to edit a text file?)

Hi Hanif,
my solution:

awk '{if (NR>=18 && match($0,"htm")) print "/work/" $0; else print}'

Best regards.
Frank.

P.D I think the last reply by Rodney Hills does not work properly because the awk script only prints lines with /htm/ pattern and does not print lines without this pattern.
Linux?. Yes, of course.