LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-07-2017, 12:17 AM   #1
sudheer113
LQ Newbie
 
Registered: Dec 2017
Posts: 2

Rep: Reputation: Disabled
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

Last edited by sudheer113; 12-07-2017 at 12:18 AM.
 
Old 12-07-2017, 12:29 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
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?
 
Old 12-07-2017, 12:35 AM   #3
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
You want only the files without SUM in the name?
Or only last field?
Probably both?

Which program do you think is needed?

OK
 
Old 12-07-2017, 07:44 AM   #4
sudheer113
LQ Newbie
 
Registered: Dec 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
Yes AnanthaP,

I want the files with out SUM in the name..
 
Old 12-07-2017, 11:57 PM   #5
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
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
 
Old 12-08-2017, 12:10 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
GNU's ls can exclude patterns using the -I option, too.
 
Old 12-08-2017, 07:24 AM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
If using bash shell, enabling extglob would allow extended matching patterns like
Code:
shopt -s extglob
ls !(*_SUM_*)

Last edited by keefaz; 12-08-2017 at 07:27 AM.
 
  


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
[SOLVED] Using a variable in sed to pick a specific line from a text file, bash Sunvic Linux - Newbie 10 08-12-2012 11:03 AM
Bash script help... menu to pick file from folder bfellenr Linux - Newbie 13 01-15-2011 03:30 PM
Find folders with ONLY one specific file in and delete file and folder - How ? gedi1 Linux - Newbie 5 10-21-2009 08:09 PM
find a folder containing a specific file amicke Linux - General 3 04-20-2009 10:04 AM
find a folder not containing a specific file itzfritz Linux - Server 2 09-10-2008 11:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:40 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