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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New Line to this output

Status
Not open for further replies.

denisl

Technical User
Jun 18, 2001
36
US
Hi,
I'm trying to spearate the output of the diff command between each result of the command with a new line but can't figure out how..
Here's a sample output from diff:
$ diff file1 file2
2d1
< ABCDEFG 12343
4c3
< ABCDEFG 12345
---
> ABCDEFG 1234x
7a7
> ABCDEFG 12341


I want to pipe it to something and make it look like this:
$ diff file1 file2 | $SOMETHING
2d1
< ABCDEFG 12343

4c3
< ABCDEFG 12345
---
> ABCDEFG 1234x

7a7
> ABCDEFG 12341

My goal here is to create a report daily that shows changes to a controlled file (audit the file). I'll copy it daily and run the diff command against it the current day and yesterday. I need to identify the a,c,d of diff and then report accordingly.. For example,
"On 9/24 ABCDEFG 1234x was ABCDEFG 12345 - This field has been CHANGED"
"On 9/24 ABCDEFG 12341 was ADDED" etc, etc..
Since I'm going to do this on AIX I plan on using grep -p to get the paragraph output of diff and then parse..

I'm struggling here... thanks!
 



Take what you have and Pipe it into


awk '/^[0..9]/ { printf("\n"); } { print $0 }'

What this tells it to do is put a NEW LINE before every line that starts with a number. SInce all the diff lines will start with <,> or --- they are exempt from the first rule. The second rule just prints every line.

---
 
I tried it but it doesn't seem to work..

$ diff file1 file2 | awk '/^[0..9]/ { printf("\n"); } { print $0 }'
2d1
< ABCDEFG 12343
4c3
< ABCDEFG 12345
---
> ABCDEFG 1234x
7a7
> ABCDEFG 12341
$ uname -s
AIX
$ oslevel
5.1.0.0

I tried doing it in a couple of steps using sed but no luck. I did this:
diff file1 file2 > diff.file
for line in `cat diff.file | grep "^[0-9]"`
do
cat diff.file | sed "s/$line/\
$line/g" > file.$$
mv file.$$ diff.file
done

However I cannot get sed to create a new line when using double quotes and a variable. If I dont use a variable and use single quotes sed works?

cat diff.file | sed '/23c24/\
23c24/g' > file.$$
mv file.$$

Thanks for you help..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top