Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

outputs the differences between two files


  • Please log in to reply
7 replies to this topic

#1 Anahita2

Anahita2

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Gender:Female
  • Local time:08:31 AM

Posted 25 June 2014 - 04:35 AM

hi guys :)

I have a question about outputing the differences between two files. I am working with Unix on MS just for a few days as part of my internship. Maybe you can help me out.

I have two txt files and would like to create a third one:

overall-list.txt, stop-word-list.txt >> out.txt.
This I would like to compare and output only the differing parts in a new list >> out.txt.

I use this: diff overall-list.txt, stop-word-list.txt >> out.txt.
with all sorts of optionen (-a,-c,-b-w etc. and develop already superstition).

It just doesn’t work...and I would be happy for some advise.

The files themselves look like this:

overall-list.txt:

a

b

c

d

e




stop-word-list.txt

a

b

c

x

y



Wishing for out.txt !

d

e


 



BC AdBot (Login to Remove)

 


#2 NickAu

NickAu

    Bleepin' Fish Doctor


  • Moderator
  • 12,927 posts
  • ONLINE
  •  
  • Gender:Male
  • Location:127.0.0.1 Australia
  • Local time:04:31 PM

Posted 25 June 2014 - 04:45 AM

sdiff file1 file2

 

 

For example,

sdiff -w 185 file1.cfg file2.cfg

 

 

You can find the difference with:

diff -a --suppress-common-lines -y a.txt b.txt

 

 

You can redirect the output in an output file (c.txt) using:

diff -a --suppress-common-lines -y a.txt b.txt > c.txt

 

You would be better of going to a Linux forum for something like this.


Edited by NickAu1, 25 June 2014 - 05:04 AM.

Arch Linux .
 
 Come join the fun, chat to Bleeping computer members and staff in real time on Discord.
 
The BleepingComputer Official Discord Chat Server!


#3 Anahita2

Anahita2
  • Topic Starter

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Gender:Female
  • Local time:08:31 AM

Posted 25 June 2014 - 05:08 AM

many thanks for your answer Nick.
I just tested it. The entire list is still maintained. My out.txt is the sum of the two lists instead of its reduction.

why is that? I just do not think that this is not supposed to work.
And its the main part of my plan "reducing content by a extern list"



#4 NickAu

NickAu

    Bleepin' Fish Doctor


  • Moderator
  • 12,927 posts
  • ONLINE
  •  
  • Gender:Male
  • Location:127.0.0.1 Australia
  • Local time:04:31 PM

Posted 25 June 2014 - 05:15 AM

No idea sorry. I am just learning this also this is an extract from some book I got.

 

Maybe this might help.

 

diff [options] file1 file2 diff [options] file1 directory diff [options] directory file2 diff [options] directory1 directory2

 

Options

   -i  --ignore-case
          Ignore case differences in file contents.

   --ignore-file-name-case
          Ignore case when comparing file names.

   --no-ignore-file-name-case
          Consider case when comparing file names.

   -E  --ignore-tab-expansion
          Ignore changes due to tab expansion.

   -b  --ignore-space-change
          Ignore changes in the amount of white space.

   -w  --ignore-all-space
          Ignore all white space.

   -B  --ignore-blank-lines
          Ignore changes whose lines are all blank.

   -I RE  --ignore-matching-lines=RE
          Ignore changes whose lines all match RE.

   --strip-trailing-cr
          Strip trailing carriage return on input.

   -a  --text
          Treat all files as text.

   -c  -C NUM  --context[=NUM]
          Output NUM (default 3) lines of copied context.

   -u  -U NUM  --unified[=NUM]
          Output NUM (default 3) lines of unified context.

   --label LABEL
          Use LABEL instead of file name.

   -p  --show-c-function
          Show which C function each change is in.

   -F RE  --show-function-line=RE
          Show the most recent line matching RE.

   -q  --brief
          Output only whether files differ.
   -e  --ed
          Output an ed script.

   --normal
          Output a normal diff.

   -n  --rcs
          Output an RCS format diff.

   -y  --side-by-side
          Output in two columns.

   -W NUM  --width=NUM
          Output at most NUM (default 130) print columns.

   --left-column
          Output only the left column of common lines.

   --suppress-common-lines
          Do not output common lines.

   -r  --recursive
          Recursively compare any subdirectories found.

A good one option is the -y --side-by-side as it will display the differences in two columns you can also use the command sdiff to reproduce the -y parameter.

 

 


Edited by NickAu1, 25 June 2014 - 05:18 AM.

Arch Linux .
 
 Come join the fun, chat to Bleeping computer members and staff in real time on Discord.
 
The BleepingComputer Official Discord Chat Server!


#5 Anahita2

Anahita2
  • Topic Starter

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Gender:Female
  • Local time:08:31 AM

Posted 25 June 2014 - 05:26 AM

Hi :)
the options work well. The total root is the Problem not the displaying.
 

Why is it that a list expands or stay just the same instead of to shrink?



#6 NickAu

NickAu

    Bleepin' Fish Doctor


  • Moderator
  • 12,927 posts
  • ONLINE
  •  
  • Gender:Male
  • Location:127.0.0.1 Australia
  • Local time:04:31 PM

Posted 25 June 2014 - 05:48 AM

Try  this.

difflib - Compare sequences - Python Module of the Week


Edited by NickAu1, 25 June 2014 - 06:03 AM.

Arch Linux .
 
 Come join the fun, chat to Bleeping computer members and staff in real time on Discord.
 
The BleepingComputer Official Discord Chat Server!


#7 Anahita2

Anahita2
  • Topic Starter

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Gender:Female
  • Local time:08:31 AM

Posted 25 June 2014 - 08:08 AM

Hi,

I couldn't work with the Information. I guess its a higher level.
 

I tried something alse. I workt with colums with only 1 Letter:

As soon as my colums are filled with more letters like words it fails..

 

join -t   -1 1 -2 1    -v1   xx.txt     yy.txt > zz.txt

 

-1 1 : use the first column(1) as the key for join in the first file(-1)
-2 1 : use the first column(1) as the key for join in the second file(-2)
-v1  : indicates to display the non-matching records of file1 and 2

 

I really would be happy for some advise.


Edited by Anahita2, 26 June 2014 - 06:19 AM.


#8 cat1092

cat1092

    Bleeping Cat


  • BC Advisor
  • 7,002 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:North Carolina, USA
  • Local time:02:31 AM

Posted 25 June 2014 - 04:25 PM

Anahita2, Welcome to BC Forums! :)

 

Unfortunately, my coding skills are no better than that of which are in the posts above, grab much of what I need on the run. The good thing is, many LInux users will seldom, if ever need these things, however I understand some will. I'm in my 5th year of being a LInux Mint user, still have a way to go, but could use it 100% of the time, if needed. 

 

Just wanted to stop in & say hello & hopefully you'll find the BleepingComputer.com site an edcuational & friendly place to learn. You have one of our 5 Star Linux assistants working with you, as he stated, there may be some things that may require outside assistance. 

 

There's a wealth of reliable information on the site, should you need to learn more & always feel free to ask questions.  :)

 

Cat


Performing full disc images weekly and keeping important data off of the 'C' drive as generated can be the best defence against Malware/Ransomware attacks, as well as a wide range of other issues. 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users