Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

output to 2 files
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


Report this thread to moderator Post Follow-up to this message
Old Post
chrishunnell@gmail.com
05-13-05 08:58 PM


Re: output to 2 files
I think it would be sufficient if it was possible to write all lines
with < in one file and all files with > in another!


Report this thread to moderator Post Follow-up to this message
Old Post
chrishunnell@gmail.com
05-13-05 08:58 PM


Re: output to 2 files

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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
05-13-05 08:58 PM


Re: output to 2 files
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 :-)
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{
}


Report this thread to moderator Post Follow-up to this message
Old Post
chrishunnell@gmail.com
05-18-05 01:55 PM


Re: output to 2 files
In 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) }


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
05-18-05 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:57 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.