Hi,
on AIX 7.1
How to compare two files ignoring blank lines?
Thanks.
Hi,
on AIX 7.1
How to compare two files ignoring blank lines?
Thanks.
Hi thank you.
I tried
diff -B file1.txt file2.txt
But:
I had: diff: 0653-821 illegal option -- B
For diff --ignore-blank-lines file1.txt file2.txt, I had the same.
Regards.
"the same" as what exactly?
What's your OS?
Have you checked man diff
?
@vgersh99 Certainly the same error message. AIX 7.1.
In a bash shell try
diff <( grep . file1.txt ) <( grep . file2.txt )
Each "process substitution" removes empty lines.
Thankyou. I tried:
$ diff <( grep . file1.txt ) <( grep . file2.txt )
ksh: syntax error: `(' unexpected
Regards.
You obviously have ksh -> ksh88.
Do you have the newer ksh93?
Or bash?
You can run a further shell, simply run
ksh93
or
bash
or substitute the current shell:
exec ksh93
If you must use sh -> ksh88 then make a function:
diffB(){ grep . "$1" > /tmp/diffB.1 && grep . "$2" > /tmp/diffB.2 && diff /tmp/diffB.1 /tmp/diffB.2; }
and use
diffB file1.txt file2.txt
The following variant even forwards simple options:
diffB(){ d_opts=""; while [[ $1 = -[!-]* ]]; do d_opts="$d_opts $1"; shift; done; grep . "$1" > /tmp/diffB.1 && grep . "$2" > /tmp/diffB.2 && diff $d_opts /tmp/diffB.1 /tmp/diffB.2; }
So you can do e.g.
diffB -c file1.txt file2.txt
Since this is AIX, the usual ksh/sh command options are not always the same/ It is IBM's flavor of those commands.
Definately look at the man page for diff. If it is not on your system, you can find it on line.
Try the -w
(lower case W). it ignores all spaces and tabs, and treats all other strings of blanks as equivalent.
If that doesn't work for you, you will need to create a temporary file without any blank lines, then compare the temp files. Other answers show you how to do this.
bash does not exist by default on AIX. bsh is the bourne shell (sh).
Good luck!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.