LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-02-2016, 09:03 AM   #1
torito
LQ Newbie
 
Registered: May 2016
Posts: 23

Rep: Reputation: Disabled
Smile which lines are identical in the two files


Hi everyone!

I am trying to write a command to find out which lines are identical in the two files.
I come up with grep -f file1 file2 > newfile

The problem is when I open newfile, it is empty. There is nothing there.

Any suggestions, please?

Thank you very much!
 
Old 06-02-2016, 09:26 AM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
Your command works for me. Maybe file1 and file2 have no lines in common.
 
Old 06-02-2016, 09:31 AM   #3
torito
LQ Newbie
 
Registered: May 2016
Posts: 23

Original Poster
Rep: Reputation: Disabled
Ummm.... interesting. I typed using vi an exact line in both files, but that line is not shown in the newfile.
 
Old 06-02-2016, 09:45 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,786

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Does file1 have any special characters in it? (e.g. ".", "*", "\", "[", "]", etc)

You should use -F (fixed strings, rather then regexps)

Code:
grep -Ff file1 file2 > newfile
 
Old 06-02-2016, 09:52 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
You could also try looking at the comm command.
 
Old 06-02-2016, 10:08 AM   #6
torito
LQ Newbie
 
Registered: May 2016
Posts: 23

Original Poster
Rep: Reputation: Disabled
Thumbs up

Thank you everyone!!!!!!!!!!!!!!!!!!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple (nearly) identical lines in dmesg when booting Slack64 14.1 paulb2 Slackware 3 11-09-2014 08:33 PM
[SOLVED] insert space between 2 identical lines papori Linux - Newbie 13 06-02-2014 02:45 AM
autofs local map files identical but not identical to automount jwaldram Linux - Server 2 10-26-2012 10:35 AM
[SOLVED] remove similar (not identical) lines of text steve51184 Linux - Software 5 04-24-2012 11:45 PM
remove identical lines in a file benjithegreat98 Linux - General 4 04-24-2004 06:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration