Code Comments
Programming Forum and web based access to our favorite programming groups.Hi! I have created a diff-file from two files and now I want to run an awk-script to write the differences in two different files. first file: das ist ein testfile und jede zeile wird mit einer anderen verglichen um die differenz zu berechnen anschliessend muss man schauen welche zeilen geupdated wurden was ich mit dieser kleinen testfile machen will second file: das ist ein testfile und jede zeile wird mit einer anderen verglichen um die differenz zu berechnen anschliessend muss man schauen welche zeilen geupdated wurden was ich mit dieser kleinen testfile machen will I have created to different diff-files but I am not quite sure which of them is better to use with awk. diff1: *** sampl1 Fr Mai 13 08:41:32 2005 --- sampl2 Fr Mai 13 09:00:24 2005 *************** *** 1,8 **** das ist ein testfile ! und jede zeile wird mit einer anderen verglichen um die differenz zu berechnen - anschliessend muss man schauen welche zeilen geupdated wurden ! was ich mit dieser kleinen testfile machen will --- 1,8 ---- das ist ein testfile ! und jed zeile wird mit einer anderen verglichen um die differenz zu berechnen zeilen geupdated wurden ! was ich mit d ieser kleinen testfile machen will + neue zeile diff2: 2c2 < und jede zeile wird mit einer anderen --- > und jed zeile wird mit einer anderen 5d4 < anschliessend muss man schauen welche 7c6 < was ich mit dieser kleinen testfile machen --- > was ich mit d ieser kleinen testfile machen 8a8 > neue zeile within the first file i can see exactly what changes there were between the two files. With the awk I want to write all changed (update/new) lines into one file and all deleted lines into another file. the main problems are the updated lines because in diff1 they appear twice for each line. I hope you have a clue what i mean because it is hard to describe it. Thanks for your help anyways! Chris
Post Follow-up to this messageI think it would be sufficient if it was possible to write all lines with < in one file and all files with > in another!
Post Follow-up to this message
chrishunnell@gmail.com wrote:
> I think it would be sufficient if it was possible to write all lines
> with < in one file and all files with > in another!
>
awk '{print > (/>/ ? "foo" : "bar")}'
Ed.
Post Follow-up to this messageHi Ed,
thanks for your help!
Your script works out if all lines have > and < but not if it has other
lines to like "---".
The file I am manipulating is the output of a diff.
My code looks like that and does what it should :-)
It reads at the beginning the name of the input-file and then it tests
whether the line starts with > or < and then writes it into 2 different
files.
I guess there is a much shorter way to express the same :-)
BEGIN{
filename=ARGV[1]
}
{
if (/^\</)
{
out_del=filename"_d.txt"
gsub ("\< ", "")
print >> out_del
}
if (/^\>/)
{
out_update_new=filename"_un.txt"
gsub ("\> ", "")
print >> out_update_new
}
}
END{
}
Post Follow-up to this messageIn article <1116407978.306815.84220@g14g2000cwa.googlegroups.com>,
chrishunnell@gmail.com <chrishunnell@gmail.com> wrote:
>Hi Ed,
>
>thanks for your help!
>Your script works out if all lines have > and < but not if it has other
>lines to like "---".
>The file I am manipulating is the output of a diff.
>My code looks like that and does what it should :-)
When I saw Ed's post, I had the same reaction - that it assumed all the
lines started with < or > - i.e., that he had forgotten that you were
working with "diff" output.
How about :
match("<>",substr($0,1,1)) { print > ("file" RSTART) }
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.