Operating System - HP-UX
1748104 Members
4543 Online
108758 Solutions
New Discussion юеВ

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

 
SOLVED
Go to solution
Hanif Kazemi
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".

harry d brown jr
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
Hanif Kazemi
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.
Rodney Hills
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...
Francisco J. Soler
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.