Combining files with specific patterns of naming in a directory


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers Combining files with specific patterns of naming in a directory
Prev   Next
# 1  
Old 11-26-2012
Question Combining files with specific patterns of naming in a directory

Greetings Unix exports,
I am facing some problems in combining files with different name patterns with a directory and I would appreciate if you can help me
I have more than 1000 files but they follow a specific pattern of naming. e.g. 64Xtest01.txt
They are divided into two sets of test and train
The Train set pattern is the following: e.g. 64XtrainY1.txt-James-Maggie.txt
Quote:
1) 2 fixed digits: 64
2) A Capital letter which may vary
3) “train”
4) Another Capital letter
5) One digit number
6) “.txt-”
7) Another pattern of “bla-bla” ---25 to 50 different names
8) .txt --- the format
The test set pattern is the following: e.g. 64xtest14.txt-James-Maggie.txt
Quote:
1) 2 fixed digits 64
2) A capital letter which may vary
3) “test”
4) Two digit number, may vary
5) “.txt-”
6) Another pattern of “bla-bla” ---25 to 50 different names
7) .txt --- the format
And each of these files have only one line in them
Now I want to combine the files that have the unique patterns before the “.txt” and combine the rest of the files in them. e.g.
Quote:
64XtrainY1.txt
64XtrainY2.txt
64YtrainX1.txt
64Xtest01.txt
64Ytest02.txt
I am wondering what is the best way to deal with it
I have tired to combine all of them into a single file and then divide them best of a line with GREP but that is not an afficient way to do it I am sure.
Code:
FILES="XXXXXXX/*"
for X in $FILES
do
	name=$(basename $X) 
	awk '{printf "%s,%s\n",FILENAME,$0}' $X 
done > test-result.txt
cat test-result.txt | grep "count/64Xtrain*" > Xtrain.txt
cat test-result.txt | grep "count/64Xtest*" >  Xtest.txt
cat test-result.txt | grep "count/64Ytrain*" > Ytrain.txt
cat test-result.txt | grep "count/64Ytest*" >  Ytest.txt
….

And then divide them based on names per line again but it’s a nightmare if u have loads of file.
So would really appreciate any helpSmilieSmilieSmilie
 
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 to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies

2. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

3. Shell Programming and Scripting

Concatenation of files with same naming patterns dynamically

Since my last threads were closed on account of spamming, keeping just this one opened! Hi, I have the following reports that get generated every 1 hour and this is my requirement: 1. 5 reports get generated every hour with the names "Report.Dddmmyy.Thhmiss.CTLR"... (5 Replies)
Discussion started by: Jesshelle David
5 Replies

4. UNIX for Dummies Questions & Answers

Combining grep patterns with OR condition?!

Hello! I have a question about how to combine patterns in grep commands with the OR operator. So I have this little assignment here: Provide a regular expression that matches email addresses for San Jose City College faculty. A San Jose City college faculty’s email address takes the form:... (1 Reply)
Discussion started by: kalpcalp
1 Replies

5. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurrence of a specific word

he following are the files available in my directory RSK_123_20141113_031500.txt RSK_123_20141113_081500.txt RSK_126_20141113_041500.txt RSK_126_20141113_081800.txt RSK_128_20141113_091600.txt Here, "RSK" is file prefix and 123 is a code name and rest is just timestamp of the file when its... (7 Replies)
Discussion started by: kridhick
7 Replies

6. Shell Programming and Scripting

How to copy a directory without specific files?

Hi I need to copy a huge directory with thousands of files onto another directory but without *.WMV files (and without *.wmv - perhaps we need to use *.). Pls advise how can I do that. Thanks (17 Replies)
Discussion started by: reddyr
17 Replies

7. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

8. Shell Programming and Scripting

Find files that do not match specific patterns

Hi all, I have been searching online to find the answer for getting a list of files that do not match certain criteria but have been unsuccessful. I have a directory that has many jpg files. What I need to do is get a list of the files that do not match both of the following patterns (I have... (21 Replies)
Discussion started by: nikos-koutax
21 Replies

9. Shell Programming and Scripting

Naming of directory problem

hi all suppose in particular directory i have lots of directory supoose 201009 201010 201011 201012 now by mistake i have rename all these directory as 201009.bk 201010.bk 201011.bk 201012.bk now how can i revert the changes back pls help me regarding this (2 Replies)
Discussion started by: aishsimplesweet
2 Replies

10. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurence of a specific word

Hello, I have several files in a specific directory. A specific string in one file can occur in another files. If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string. Example. file1 ShortName "Blue... (2 Replies)
Discussion started by: premier_de
2 Replies
Login or Register to Ask a Question