Diff creating special characters in output file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Diff creating special characters in output file
# 1  
Old 03-03-2009
Diff creating special characters in output file

Hi
I am comparing 2 files (using diff command) with numerical data in them. In the output file I want only the differences which are in file2 but not in file1. Although I am getting the diffences i am also getting special characters in the output file which i do not want. Can somebody help me
For reference i am giving my 2 input file and the output file I am getting

Input file1.txt

101
102
103
104
105
106

Input file2.txt

104
108
106

After diff file1.txt file2.txt result.txt

Output file Result.txt

1,3d0
< 101
< 102
< 103
6c2
< 105
----
> 108

However in output I only want
101
102
103
105
# 2  
Old 03-03-2009
Hi.

As noted at the bottom of the thread page, https://www.unix.com/unix-dummies-que...haracters.html has several suggestions ... cheers, drl
# 3  
Old 03-04-2009
This might help you...

Code:
$ diff infile1 infile2 | grep "<" | awk -F "<" '{print $2}' | cut -c2-

101
102
103
105

Or

diff in1 in2 | grep "<" | cut -c3-

Or simple code

grep -vf infile2 infile1

Pls use the search option before posting questions... there are lot of similar threads like thisSmilie

Last edited by Whiteboard; 03-04-2009 at 05:49 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Rename File Name with Special Characters

I am trying to rename files with spaces and other characters and not able to be successful. FileNames: UPLOAD REFERENCE.xls UPLOAD MASS REFERENCE.XLS find /UPLOAD REFERENCE/ -depth -type f -name "* *" -exec rename " " "_" "{}" ";" The above one is successful to replace spaces... (1 Reply)
Discussion started by: eskay
1 Replies

2. Red Hat

Special control characters in file

Hi Guys, We receive some huge files on to Linux server. Source system use FTP mechanism to transfer these files on our server. Occasionally one record is getting corrupted while transfer, some control characters are injecting into the file. How to fix this issue ? please advice ? Sample... (2 Replies)
Discussion started by: srikanth38
2 Replies

3. Shell Programming and Scripting

File containing special characters

Hello All, I am facing challenges in order to transfer a file from windows to unix box,the file contains a special character '×' ,now when I am transferring the file from windows to unix that special character converted to something else like 'Ã' ,another thing I have noticed that the hardware is... (1 Reply)
Discussion started by: prarat
1 Replies

4. Shell Programming and Scripting

Problem with Special characters in file

Hi, I am facing a below problem. Inorder to mak sure the below file is fixed width i am using the following command awk '{printf("%-375s\n", $0) } so as to add trailing spaces at the end for records of length less than 375. Input file > inp.txt 1©1234 1234 123©1 The output file is... (1 Reply)
Discussion started by: marcus_kosaman
1 Replies

5. Shell Programming and Scripting

Is there anyway to grep any special characters from a file ?

Is there any command or shell script to grep any special character from a file ? I have a huge file containing millions of user names; the requirement is to find names containing special characters. #!/bin/bash for i in `cat username.txt` do #COMMAND to grep special character done ... (3 Replies)
Discussion started by: poga
3 Replies

6. Shell Programming and Scripting

escaping special characters in file name...

dear, I would like to rename files in a dir to another format, so I write a bash shell script to handle it. But my problem now is how to handle files having special characters like spaces, (, ): "a b c (d).doc" It seems that I need to escape those characters before applying the "mv" command.... (1 Reply)
Discussion started by: lau0001
1 Replies

7. UNIX for Dummies Questions & Answers

Diff output, unwanted characters

I've got a diff command running in a shell script that writes the ouput to a new file. In the new file there is a ">" at the beginning of each line. The output file is going to be used by another program and that character makes the file useless. What I'm getting in the new file: > 2007-09-27... (5 Replies)
Discussion started by: scanner248
5 Replies

8. UNIX for Dummies Questions & Answers

Replace Special characters in a file

Hi, I have a data like this in a file, 402003279034002000100147626030003300010000000000002000029000000 ær^M^\MÍW^H I need to replace those special char to some other char like # or $ Is there any ways to do it... I tried commands tr,sed and many but it was not able to replace because... (1 Reply)
Discussion started by: solai
1 Replies

9. UNIX for Dummies Questions & Answers

how to see special characters in a file using vi

Hi, I have a file which has special characters. I can't see them when I "vi" the file. But I am sure there are some special un seen characters. How can I see them? Please help. Thx (6 Replies)
Discussion started by: jingi1234
6 Replies

10. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies
Login or Register to Ask a Question