LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Pick the specific format file in the folder (https://www.linuxquestions.org/questions/programming-9/pick-the-specific-format-file-in-the-folder-4175619115/)

sudheer113 12-07-2017 12:17 AM

Pick the specific format file in the folder
 
I want pick the specific format of file among the list of files in a directory from linux. Please find the below example.

I have a below list of files (6 files).

Set-1 1) MAG_L_NT_AA_SUM_2017_01_20.dat 2) MAG_L_NT_AA_2017_01_20.dat

Set-2 1) MAG_L_NT_BB_SUM_2017_01_20.dat 2) MAG_L_NT_BB_2017_01_20.dat

Set-3 1) MAG_L_NT_CC_SUM_2017_01_20.dat 2) MAG_L_NT_CC_2017_01_20.dat

From the above three sets I need only 3 files. 1) MAG_L_NT_AA_2017_01_20.dat 2) MAG_L_NT_BB_2017_01_20.dat 3) MAG_L_NT_CC_2017_01_20.dat

Note: There can be multiple lines of commands because i have create the script for above req. Thanks

Turbocapitalist 12-07-2017 12:29 AM

Welcome.

It looks like you are dealing with the file names and not the format they contain. You should be able to work out a pattern based on similarities and then use ls to show you the name of the files that match the pattern. See "man 7 glob" for the basics of that.

What have you tried so far and where are you stuck?

AnanthaP 12-07-2017 12:35 AM

You want only the files without SUM in the name?
Or only last field?
Probably both?

Which program do you think is needed?

OK

sudheer113 12-07-2017 07:44 AM

Yes AnanthaP,

I want the files with out SUM in the name..

AnanthaP 12-07-2017 11:57 PM

The exact format of the file isn't apparent. Does each line have 3 fields?

Anyway the pseudo code is:
For each line
--- For each field
--- If it doesn't start with SET and doesn't contain SUM, then pick it for further action.

Now think about what packages (sed, awk, grep ..) you would use and how you would go about it.

OK

Turbocapitalist 12-08-2017 12:10 AM

GNU's ls can exclude patterns using the -I option, too.

keefaz 12-08-2017 07:24 AM

If using bash shell, enabling extglob would allow extended matching patterns like
Code:

shopt -s extglob
ls !(*_SUM_*)



All times are GMT -5. The time now is 02:40 PM.