Grouping files on pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grouping files on pattern
# 8  
Old 11-14-2017
Hi Don Cragun,
My requirement is litle bit changed..instaed creating dynamic dir i want to send to these files to file list but not all files together rather first only one group set of files and then second group set.
So i am using this code
Code:
#!/bin/bash
cd /apps/sym/arcload/VSORT_X9/test
FILE_LIST=/apps/sym/arcload/VSORT_X9/SrcFiles/Source_input.txt
for file in *[_-]S[_-]*[_-]*[_-]*[_-][0-9][0-9][0-9][0-9][01][0-9][0-3][0-9][_-][0-2][0-9][0-6][0-9][0-6][0-9].txt
do      IFS='[_-]'
        set -- $file
        unset IFS
        echo "$file" >> $FILE_LIST
done

but here problem is its writing all files to the file list...i want to send first 4 grouped files do operation on that and same operation for next 2 grouped files and so on..

thanks for your help againSmilie
# 9  
Old 11-14-2017
Quote:
Originally Posted by gnnsprapa
Hi Don Cragun,
My requirement is litle bit changed..instaed creating dynamic dir i want to send to these files to file list but not all files together rather first only one group set of files and then second group set.
So i am using this code
Code:
#!/bin/bash
cd /apps/sym/arcload/VSORT_X9/test
FILE_LIST=/apps/sym/arcload/VSORT_X9/SrcFiles/Source_input.txt
for file in *[_-]S[_-]*[_-]*[_-]*[_-][0-9][0-9][0-9][0-9][01][0-9][0-3][0-9][_-][0-2][0-9][0-6][0-9][0-6][0-9].txt
do      IFS='[_-]'
        set -- $file
        unset IFS
        echo "$file" >> $FILE_LIST
done

but here problem is its writing all files to the file list...i want to send first 4 grouped files do operation on that and same operation for next 2 grouped files and so on..

thanks for your help againSmilie
I do not understand what you are trying to do, so I don't see how I can help you.

You have removed all of the code that created groups of files, so I don't know what groups you are now talking about.

The code you have shown above could be replaced by the much simpler code:
Code:
#!/bin/bash
cd /apps/sym/arcload/VSORT_X9/test
FILE_LIST=/apps/sym/arcload/VSORT_X9/SrcFiles/Source_input.txt
printf '%s\n' > "$FILE_LIST"  *[_-]S[_-]*[_-]*[_-]*[_-][0-9][0-9][0-9][0-9][01][0-9][0-3][0-9][_-][0-2][0-9][0-6][0-9][0-6][0-9].txt

Please show us a brief list of filenames you want to process and then clearly explain how you decide which four files to process first, which two files to process next, and so on. And, clearly explain what operation you want to perform on each group of files.

Note that if the directories you created in your earlier problem are the groups you're talking about now, the list of files in your output file is not sorted into groups in any manner (and files that would have been grouped together in directories will not necessarily even be adjacent to each other in the output file produced by your code above).

More importantly, if you didn't understand the answers I provided in post #7 in this thread for your questions, please ask more questions. Our goal here is to help you learn how to write your own code. We are not here to act as your unpaid programming staff.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to grouping time and based on value with multiple pattern?

Hi All, need help... I have some log below : ### {"request_id":"e8395eb0-a8bd-11e9-b77b-d507ea5312aa","message":"when inquiry paybill 628524871 prevalidation cause : Invalid Transaction"} ### {"request_id":"043f2310-a8be-11e9-b57b-f9c7344998d7","message":"when inquiry paybill 62821615... (2 Replies)
Discussion started by: fajar_3t3
2 Replies

2. Shell Programming and Scripting

grouping log files based on counter

I have my log file as below 00:18:02 - Nothing normal; Garbage Collection kicked off & running from last 3 min... 00:19:02 - Nothing normal; Garbage Collection kicked off & running from last 4 min... 00:19:02 - Nothing normal; Garbage Collection kicked off & running from last 4 min...... (11 Replies)
Discussion started by: manas_ranjan
11 Replies

3. Shell Programming and Scripting

Grouping files according to certain fields in their name

I have a list of fils stored insortedLst, and want to select certain fields to group specific files together: Example of the files would be as below: n02-z30-dsr65-ndelt0.25-varp0.002-16x12drw-run1.log n02-z30-dsr65-ndelt0.25-varp0.002-16x12drw-run2.log... (2 Replies)
Discussion started by: kristinu
2 Replies

4. Shell Programming and Scripting

combine 3 files by grouping

I have a file, which is really large but i shortened it: A3059GVS 1 A 01 Plate_1 40 25.37016 14.6298 A3059GVS 2 A 01 Plate_2 40 26.642002 13.3583 A3059GVS 3 A 02 Plate_1 40 25.381462 ... (4 Replies)
Discussion started by: mykey242
4 Replies

5. Shell Programming and Scripting

Searching across multiple files if pattern is available in all files searched

I have a list of pattern in a file, I want each of these pattern been searched from 4 files. I was wondering this can be done in SED / AWK. say my 4 files to be searched are > cat f1 abc/x(12) 1 abc/x 3 cde 2 zzz 3 fdf 4 > cat f2 fdf 4 cde 3 abc 2... (6 Replies)
Discussion started by: novice_man
6 Replies

6. Shell Programming and Scripting

Find required files by pattern in xml files and the change the pattern on Linux

Hello, I need to find all *.xml files that matched by pattern on Linux. I need to have written the file name on the screen and then change the pattern in the file just was found. For instance. I can start the script with arguments for keyword and for value, i.e script.sh keyword... (1 Reply)
Discussion started by: yart
1 Replies

7. Shell Programming and Scripting

parsing file names and then grouping similar files

Hello Friends, I have .tar files which exists under different directories after the below code is run: find . -name "*" -type f -print | grep .tar > tmp.txt cat tmp.txt ./dir1/subdir1/subdir2/database-db1_28112009.tar ./dir2/subdir3/database-db2_28112009.tar... (2 Replies)
Discussion started by: EAGL€
2 Replies

8. Shell Programming and Scripting

Grouping files into tars

Hi all, I have a problem where i have several files in a directory which I SCP from a server to my local machine and i would like to periodically tar/gzip them based on their naming convention. Here is the scenario: I SCP files (which all end with the same ending) periodically across to a... (3 Replies)
Discussion started by: muay_tb
3 Replies

9. UNIX for Dummies Questions & Answers

copying a pattern of files in one directory into other with new pattern names...

Hi, I have to copy a set of files abc* in /path/ to /path1/ as abc*_bkp. The list of files appear as follows in /path/: abc1 xyszd abc2 re2345 abcx .. . abcxyz I have to copy them (abc* files only) into /path1/ as: abc1_bkp abc2_bkp abcx_bkp .. . (6 Replies)
Discussion started by: new_learner
6 Replies

10. Shell Programming and Scripting

Pattern searching pattern in c files

I have a problem in searching a specific pattern in c files. My requirement: I have to find all the division operator in all cfiles. The problem is, the multi line comments and single line comments will also have forward slash in it. Even after avoiding these comments also, if both... (6 Replies)
Discussion started by: murthybptl
6 Replies
Login or Register to Ask a Question