|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Diff command
Hi,
I am having two files. Data in both the files are as File 1 : BCSU-1 0032 WO-EX - BCSU-2 0034 SP-EX - BCSU-3 0045 WO-EX - BCSU-4 0046 WO-EX - File 2: BCSU-1 0032 SP-EX - BCSU-3 0045 WO-EX - I need a command which will compare these two files and give me an output as, BCSU-2 0034 SP-EX - BCSU-4 0046 WO-EX - In short, the output file should not contain those lines where common first word exists. I tried using diff command, but it compares the whole line instead of comparing only the first word. Please let me know how to tackle this problem. BR Nevil |
|
#2
|
||||
|
||||
|
Not sure what kind of shell you're using. With bash or ksh, this works fine:
Code:
for i in `awk '{print $1}' file1`
do
if ! grep $i file2 >/dev/null 2>&1
then
grep $i file1
fi
if ! grep $i file1 >/dev/null 2>&1
then
grep $i file2
fi
done
If either file has more than one line that starts with "BCSU-2" (as an example) then this hack might not work properly. |
|
#3
|
|||
|
|||
|
Its worked for me. Thanks a ton.
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Diff command |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|