LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 01: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 01:18 AM.
 
Old 12-07-2017, 01:29 AM   #2
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 2,688
Blog Entries: 3

Rep: Reputation: 1168Reputation: 1168Reputation: 1168Reputation: 1168Reputation: 1168Reputation: 1168Reputation: 1168Reputation: 1168Reputation: 1168
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, 01:35 AM   #3
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 855

Rep: Reputation: 203Reputation: 203Reputation: 203
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, 08: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-08-2017, 12:57 AM   #5
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 855

Rep: Reputation: 203Reputation: 203Reputation: 203
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, 01:10 AM   #6
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 2,688
Blog Entries: 3

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

Rep: Reputation: 420Reputation: 420Reputation: 420Reputation: 420Reputation: 420
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 08:27 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

All times are GMT -5. The time now is 05:02 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration