![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Comparing two files using awk | kanu_kanu | Shell Programming and Scripting | 2 | 09-16-2008 08:30 AM |
| Comparing two files | guptan | Shell Programming and Scripting | 5 | 08-04-2008 09:02 AM |
| Comparing two txt files - pls help | jisha | Shell Programming and Scripting | 5 | 01-23-2008 04:14 AM |
| Comparing two files | kingofprussia | UNIX for Dummies Questions & Answers | 2 | 08-01-2007 01:25 PM |
| comparing shadow files with real files | terrym | UNIX for Advanced & Expert Users | 4 | 02-09-2007 02:38 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi,
some one please help me I have two files.each having two coloumns and many rows I want to write the difference between the two files to a new file sample: file1 1 2 4 5 8 6 file2 1 2 3 5 8 4 3 6 9 7 I tried with 'diff' and 'comm' commands.i got the output that include differenet rows in both the files as well as extra rows in second file. I got the output as. 4 5 3 5 8 4 8 6 3 6 9 7 but I want the output like 4 5 3 5 8 4 8 6 I want only the changes in rows from first file to second file in the output.Not the extra rows in table 2. Please guide me regards bab123 |
|
||||
|
An inefficent way in shell script would be to read file1 record-by-record then look at the corresponding record in file2. This script is unsuitable for large files and would be better in awk where you could read a both files in parallel.
The script assumes that file1 does not contain more records than file2. #!/bin/ksh COUNTER=0 cat file1|while read LINE1 do COUNTER=`expr $COUNTER + 1` LINE2=`cat file2|head -${COUNTER}|tail -1` if [ ! "${LINE1}" = "${LINE2}" ] then echo "${LINE1}" echo "${LINE2}" fi done |
![]() |
| Bookmarks |
| Tags |
| shell script, shell scripting, unix scripting, unix scripting basics |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|