Find common lines between all of the files in one folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find common lines between all of the files in one folder
# 1  
Old 03-03-2018
Find common lines between all of the files in one folder

Could it be possible to find common lines between all of the files in one folder? Just like comm -12 . So all of the files two at a time. I would like all of the outcomes to be written to a different files, and the file names could be simply numbers - 1 , 2 , 3 etc. All of the file names contain dash signs, usually they have between one and six dash signs, I hope it won't disturb? The folder has a 100 files or more , sometimes I have to work even with 200 files.
Sincerely grateful if anyone can help!
# 2  
Old 03-03-2018
Of course it is possible... Why don't you start with some of the suggestions in your first thread in this forum Find common lines with one file and with all of the files in another folder and build on top of that to do what you're requesting here.

Please, when starting a thread in this forum, always tell us what operating system and shell you're using so we don't waste our time making suggestions that won't work in your environment. And, tell us whether or not our suggestions work for you (and if not) tell us clearly what worked and what didn't.

If you keep on just making requests and don't do any of the work yourself, it'll get really boring for us to waste time trying to help you and you won't learn anything from our efforts. We want to help you learn how to do things like the on your own; not to act as your unpaid programming staff.
# 3  
Old 03-03-2018
Pretty sure, yes. More details would help, as always. How would you approach the problem, given the proposals in your other thread , adapted to the new problem?
# 4  
Old 03-03-2018
What have you tried so far?

And please give us examples of the filenames.

The way you worded it, we can find only duplicates in two files. Once we move to the next two we would find a possibly distinct set of new duplicate lines.

If you actually want a set of lines that are duplicated anywhere the logic look like this
Code:
awk '{arr[0]++ }  END {for(i in arr) { if(arr[i]>1) {print i } } \
           find . -type f -name 'filenames_I_want*'  > my_duplicated_lines

EDIT: oops we all answered at the same time....

We need lots of clarification to help....
# 5  
Old 03-03-2018
I'm really sorry for the inconvenience caused...
This thread is my last question to you, if I can get it working I won't bother you again.
I'm using Windows 7 and Unix subsystems for Windows. I'm using C Shell.

And the filename examples are:
Code:
AC-FOUR-136-ZEL2-ZECO-111
AC-SEVEN-56-ZEL4-ZECO-68
AC-NINE-994-ZEL3-ZECO-811
AC-ONE-4-ZEL1-ZECO-544
AC-NINE-4-53-ZEL3-ZECO-811
AC-ELEVEN-66-788-ZEL4-ZECO-87
AC-TWO-32-7788-ZEL4-ZECO-95
AC-SIX-56-111-ZEL4-ZECO-87
AC-FOURTEEN-59-1561-ZEL2-ZECO-5


In case of this solution I got an error - Unmatched '
I noticed that there is also an unequal number of these signs { } could it be a problem?

Code:
awk '{arr[0]++ }  END {for(i in arr) { if(arr[i]>1) {print i } } \
           find . -type f -name 'filenames_I_want*'  > my_duplicated_lines

---------- Post updated at 05:46 PM ---------- Previous update was at 05:38 PM ----------

I forgot to mention that all of the files are sorted

Last edited by Scrutinizer; 03-04-2018 at 12:51 AM.. Reason: code tags
# 6  
Old 03-05-2018
Edited code - please see correction above.
# 7  
Old 03-06-2018
What do you want to compare?
File names or file contents?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to trim folder and files within a path that share a common file extension

The bash will trim the folder to trim folder. Within each of the folders (there may be more than 1) and the format is always the same, are several .bam and matching .bam.bai files (file structure) and the bashunder that executes and trims the .bam as expected but repeats the.bam.bai extentions... (9 Replies)
Discussion started by: cmccabe
9 Replies

2. Shell Programming and Scripting

Find common lines with one file and with all of the files in another folder

Hi! I would like to comm -12 with one file and with all of the files in another folder that has a 100 files or more (that file is not in that folder) to find common text lines. I would like to have each case that they have common lines to be written to a different output file and the names of the... (6 Replies)
Discussion started by: Eve
6 Replies

3. Shell Programming and Scripting

Shell Script to find common lines and replace next line

I want to find common line in two files and replace the next line of first file with the next line of second file. (sed,awk,perl,bash any solution is welcomed ) Case Ignored. Multiple Occurrence of same line. File 1: hgacdavd sndm,ACNMSDC msgid "Rome" msgstr "" kgcksdcgfkdsb... (4 Replies)
Discussion started by: madira
4 Replies

4. UNIX for Dummies Questions & Answers

Filter lines common in two files

Thanks everyone. I got that problem solved. I require one more help here. (Yes, UNIX definitely seems to be fun and useful, and I WILL eventually learn it for myself. But I am now on a different project and don't really have time to go through all the basics. So, I will really appreciate some... (6 Replies)
Discussion started by: latsyrc
6 Replies

5. Shell Programming and Scripting

Find common lines between multiple files

Hello everyone A few years Ago the user radoulov posted a fancy solution for a problem, which was about finding common lines (gene variation names) between multiple samples (files). The code was: awk 'END { for (R in rec) { n = split(rec, t, "/") if (n > 1) dup = dup ?... (5 Replies)
Discussion started by: bibb
5 Replies

6. Shell Programming and Scripting

Common lines from files

Hello guys, I need a script to get the common lines from two files with a criteria that if the first two columns match then I keep the maximum value of the 5th column.(tab separated columns) . 3rd and 4th columns corresponds to the row which has highest value for the 5th column. Sample... (2 Replies)
Discussion started by: jaysean
2 Replies

7. Shell Programming and Scripting

Common lines from files

Hello guys, I need a script to get the common lines from two files with a criteria that if the first two columns match then I keep the maximum value of the 3rd column.(tab separated columns) Sample input: file1: 111 222 0.1 333 444 0.5 555 666 0.4 file 2: 111 222 0.7 555 666... (5 Replies)
Discussion started by: jaysean
5 Replies

8. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

9. UNIX for Dummies Questions & Answers

find common lines using just one column to compare and result with all columns

Hi. If we have this file A B C 7 8 9 1 2 10 and this other file A C D F 7 9 2 3 9 2 3 4 The result i´m looking for is intersection with A B C D F so the answer here will be (10 Replies)
Discussion started by: alcalina
10 Replies

10. Shell Programming and Scripting

To find all common lines from 'n' no. of files

Hi, I have one situation. I have some 6-7 no. of files in one directory & I have to extract all the lines which exist in all these files. means I need to extract all common lines from all these files & put them in a separate file. Please help. I know it could be done with the help of... (11 Replies)
Discussion started by: The Observer
11 Replies
Login or Register to Ask a Question