reformat the output from "diff" command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reformat the output from "diff" command
# 1  
Old 02-28-2005
reformat the output from "diff" command

Hi all,

I use the diff command and got the output:

Code:
$> diff -e file1.txt file2.txt
15a
000675695	Yi Chen	Chen	200520	EASY	50	2/28/05 0:00	SCAD Debit Card Charge
.
12a
000731176	Sarah	Anderson	200520	EASY	25	2/28/05 0:00	SCAD Debit Card Charge
.
11a
000624694	Meagan	Thomas	200520	EASY	402	2/28/05 0:00	SCAD Debit Card Charge
000679538	Nicole	Blackmon	200520	EASY	750	2/28/05 0:00	SCAD Debit Card Charge
.
2a
000679668	Ashley	Tucker	200520	EASY	200	2/28/05 0:00	SCAD Debit Card Charge
000672299	Candace	Daniels	200530	EASY	100	2/28/05 0:00	SCAD Debit Card Charge
.

How do i get rid of the line above the data?

I used "comm" and it works for the format, but sometimes it doens't give me the right results, maybe i change the .xls files to .txt files

Thanks

CT

Last edited by CamTu; 02-28-2005 at 05:52 PM..
# 2  
Old 02-28-2005
If I understand your question correctly, you just want to be left with a the list of rows that need to be added to file1 in order to make it identical to file2, and you don't care about the actual position of these rows within the output (as you want to remove the 15a, 11a, etc...)?

If so, pass the output through sed
Code:
diff -e file1.txt file2.txt | sed -e '/^\.$/d' -e '/^[0-9][0-9]*a$/d'

This assumes that you all operations are "appends" (if not, modify the second sed expression to account for it), and that you don't want the rows containing just a "dot" (these are produced because of the -e option to diff which produces an "ed" script)....

If this doesn't help, please post sections of the two input files, and state exactly what results you are expecting to achieve (i.e. what exactly are you attempting to do?).

Cheers
ZB
# 3  
Old 02-28-2005
zazzybob,

Thanks for your response, that's exactly what i am looking forSmilie
But i was just wondering, if i want the output in the actual position of these row within the output file, what is the code like? for instant, i want to get rid of those lines with 1a2,3, 4a7, 7a11, 10a15 and the ">" in front of the line.

Code:
$ > diff 1.txt 2.txt
1a2,3
> 000685115     Ariel   Wilchek 200520  EASY    150     2/28/05 0:00    SCAD Deb
it Card Charge
> 000686937     Charles Payne   200520  EASY    200     2/28/05 0:00    SCAD Deb
it Card Charge
4a7
> 000735567     Hayden  Lewis   200520  EASY    50      2/28/05 0:00    SCAD Deb
it Card Charge
7a11
> 000701166     Kyle    Provencal       200520  EASY    500     2/28/05 0:00
SCAD Debit Card Charge
10a15
> 000014514     Tiffany Jennings        200520  EASY    65      2/28/05 0:00
SCAD Debit Card Charge

Once again....thanks !

CT
# 4  
Old 03-01-2005
Try as,

diff 1.txt 2.txt | sed '/^[0-9]a.*$/d;s/^>[ ]//'

HTH.
# 5  
Old 03-01-2005
Code:
diff file1.txt file2.txt | sed -e '/^[0-9][0-9a,]*$/d' -e 's/> //'

But you're still deleting the positional information, but this appears to be what you are requesting.

Cheers
ZB
# 6  
Old 03-01-2005
hey guys,

Thanks alot.....Smilie

CT
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do I redirect output from "find", either to a file or another command?

I'm trying to find out what happened to the rogue game that apt-get told me it installed, so I thought I would find the file. I went to the root and entered: find -name "rog*.*" I get a large number of lines saying my access is denied in various directories. I figure I'll practice my Unix... (14 Replies)
Discussion started by: arghvark
14 Replies

2. Programming

Redirecting output to new file for command "perldoc perllocal"

Hi, I have to redirect output of the command "perldoc perllocal" to new file which contains all the perl module installed. Currently using perldoc perllocal >> mod_data This does not contain all perl modules installed locally on machine, and each character is doubled. Please... (3 Replies)
Discussion started by: asak
3 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

Help with selecting files from "diff" output

I have two directories Dir_A and Dir_A_Arc. Need help with a shell script. The shell script needs to take the path to these two directories as parameters $1 and $2. The script needs to check if any files exist in these directories and if either of the directories are empty then exit... (5 Replies)
Discussion started by: gaurav99
5 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Retrieve RAM memory size from "top" command output

Hi, I am trying to get the system RAM size from "top" command's output by the following but it is not working. top | sed "s/^Mem.**\(*\), *//" (10 Replies)
Discussion started by: royalibrahim
10 Replies

7. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

8. UNIX for Dummies Questions & Answers

Explanation of "total" field in "ls -l" command output

When I do a listing in one particular directory (ls -al) I get: total 43456 drwxrwxrwx 2 root root 4096 drwxrwxrwx 3 root root 4096 -rwxrwxr-x 1 nobody nobody 3701594 -rwxrwxr-x 1 nobody nobody 3108510 -rwxrwxr-x 1 nobody nobody 3070580 -rwxrwxr-x 1 nobody nobody 3099733 -rwxrwxr-x 1... (1 Reply)
Discussion started by: proactiveaditya
1 Replies

9. Debian

Debian: doubt in "top" %CPU and "sar" output

Hi All, I am running my application on a dual cpu debian linux 3.0 (2.4.19 kernel). For my application: <sar -U ALL> CPU %user %nice %system %idle ... 10:58:04 0 153.10 0.00 38.76 0.00 10:58:04 1 3.88 0.00 4.26 ... (0 Replies)
Discussion started by: jaduks
0 Replies

10. UNIX for Dummies Questions & Answers

Maximum input file size in "Diff" Command

Hello, Can anyone let me know what is the maximum file size that can be given as input for the "Diff" Command in Unix? I have a file size as large as 28MB and which can also increase. Will I face any issues with such a file size. If yes, What is the other alternative. Thanks in advance for... (1 Reply)
Discussion started by: Neeraja
1 Replies
Login or Register to Ask a Question