Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy from pattern to the enf of file 1

Status
Not open for further replies.

cbsm

Programmer
Oct 3, 2002
229
FR
Hello,
I'm sorry to post this probably very simple question ...
I need to copy from a file into another from the line with pattern '123' to the end of the file.
I know how to do it from pattern1 to pattern2 :
awk '/pattern1/,/Pattern2/' /${File1} >> ${File2}

but I need something like
awk '/pattern1/,EOF' /${File1} >> ${File2}

Thank you !!!
 
One way:
awk '/pattern1/{++i}i' /${File1} >> ${File2}
Another way:
sed -n '/pattern1/,$p' /${File1} >> ${File2}

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks !
awk solution doesn't seem to work.
But sed did the job !
 
Hi

cbsm said:
I know how to do it from pattern1 to pattern2 :
awk '/pattern1/,/Pattern2/' /${File1} >> ${File2}
So the range starts on the line where matching the first expression results true, and stops on the line where matching the second expression results true.

Now your goal is that range never ends ( at least not before the file ends ). So just use a second expression which never evaluates to true.

The simplest is to hardcode a false value as second expression ( in AWK 0 and "" are false values ) :
Code:
awk '/pattern1/,[red]0[/red]' /${File1} >> ${File2}
Tested with [tt]gawk[/tt], [tt]mawk[/tt] and original [tt]awk[/tt].

( By the way, PHV's AWK code works for me with the above enumerated interpreters. )


Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top