List only required files in single command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers List only required files in single command
# 1  
Old 08-10-2015
List only required files in single command

Hello,
I would like to combine below 2 commands (list, egrep) them into a single command and list only the required files using AWK or anything else. Could you please help.

Code:
ls *FA_GL_10K_TND_HIER*dat | egrep "UPD|INS|DEL"
GL_FA_GL_10K_TND_HIER_DEL_LRF_GeneralLedgerJournalActivityCreated_1_20150810175031_8162.dat
GL_FA_GL_10K_TND_HIER_INS_LRF_GeneralLedgerJournalActivityCreated_1_20150810175031_8162.dat
GL_FA_GL_10K_TND_HIER_UPD_LRF_GeneralLedgerJournalActivityCreated_1_20150810175031_8162.dat

Thank you.
# 2  
Old 08-10-2015
How about just one ls?
Code:
ls *FA_GL_10K_TND_HIER_{UPD,INS,DEL}*dat

I fear I might not be understanding you.
# 3  
Old 08-11-2015
You might want to complement Aia's proposal with an option for leading patterns:
Code:
ls *FA_GL_10K_TND_HIER_{UPD,INS,DEL}*dat *{UPD,INS,DEL}*FA_GL_10K_TND_HIER_*dat

# 4  
Old 08-11-2015
One command?
Code:
perl -e '$\ = $, = "\n"; opendir $dh, "."; print grep { /FA_GL_10K_TND_HIER/ && ( /UPD/ || /INS/ || /DEL/ ) } readdir $dh;'

or sorted results:
Code:
perl -e '$\ = $, = "\n"; opendir $dh, "."; print sort grep { /FA_GL_10K_TND_HIER/ && ( /UPD/ || /INS/ || /DEL/ ) } readdir  $dh;'

If you don't mind using two commands:
Code:
ls -fA | awk '/FA_GL_10K_TND_HIER/ && ( /UPD/ || /INS/ || /DEL/ )'

Using ls -fA gets rid of the shell expansion which could take some time depending on the number of entries in the current directory. Or fail, if the length of the command line or the number of entries exceeds your shell's limits for either. The results would be unsorted, but that could be easily solved:
Code:
ls -fA | awk '/FA_GL_10K_TND_HIER/ && ( /UPD/ || /INS/ || /DEL/ )' | sort


Last edited by derekludwig; 08-11-2015 at 07:46 AM.. Reason: typo
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move multiple files to different directory using a single command

I have multiple files test1, test2, test3 etc. I want to move to a different directory with ABC_ prefixed to every file and and current dat time as postfix using a single command. (I will be using this is sftp with ! (command for local server). I have tried the following but it gives error ... (5 Replies)
Discussion started by: Soham
5 Replies

2. Shell Programming and Scripting

Help required to Print Single quote into a file

Hi, I need help in printing string enclosed with single quotes to a file. I am trying to write a shell script which when run will create another script below is the script logic. cat create_script.sh echo '#!/bin/sh' > append_flname.sh echo 'for FILE in $*' >> append_flname.sh echo... (6 Replies)
Discussion started by: imrandec85
6 Replies

3. UNIX for Dummies Questions & Answers

Sftp multiple files in single command

Hi All, I would like to sftp 2 files with a single command. I tried the below options, sftp suer@test13:"/u01/home/oracle/SetDb.sh /u01/home/oracle/.profile" ./ But what actually happens is Fetching /u01/home/oracle/SetDb.sh to /u01/home/oracle/.profile /u01/home/oracle/SetDb.sh ... (3 Replies)
Discussion started by: sid2013
3 Replies

4. Shell Programming and Scripting

Single command to create multiple empty files(no trailing lines as well).

Hi, i need a single command to create multiple empty files(no trailing lines as well) and empty the files if already existing. please let me know or if this has been ansered, if some ocan share the link please, thanks > newfile.txt or :> newfile.txt do not work (4 Replies)
Discussion started by: Onkar Banerjee
4 Replies

5. Shell Programming and Scripting

Incorrect number of command line arguments and missing required files

I am developing a script. This script takes in one parameter which is the name of a file whose content is a list of names of some files. The script can check whether those files exist in current directory. Here is my question: If the number of provided parameters is less than one or one of the... (2 Replies)
Discussion started by: Ray Sun
2 Replies

6. Shell Programming and Scripting

List no. of files in a directory/sub dir's and also an consolidated report as required

Need help on below query asap. Thanks. The below is the directory structure: /home/suren under /suren the following are the directories /bin /log /error /bin contains the following files abc.txt bcd.ksh cde.sh wer.ksh ghi (file with out any extension) /log contains the following... (1 Reply)
Discussion started by: sureng
1 Replies

7. Shell Programming and Scripting

Single command - unzip files from a tar command

I have a tar file that contains multiple .Z files. Hence I need to issue a tar command followed by a gzip command to fully extract the files. How do I do it in a single command? What I'm doing now is tar xvf a.tar (this will output 1.Z and 2.Z) gzip -d *.Z (to extract 1.Z and 2.Z) (9 Replies)
Discussion started by: ericlim
9 Replies

8. UNIX for Dummies Questions & Answers

List several files into one single column

frtgyh (2 Replies)
Discussion started by: lucasvs
2 Replies

9. Shell Programming and Scripting

Empty out multiple files with a single command?

I have a log directory: /logs/foo.log /logs/bar.log /logs/err.out I'm trying to find a way to > /logs/*.log > /logs/*.out to blank them out, but of course, that doesn't work. Any suggestions? (4 Replies)
Discussion started by: Validatorian
4 Replies

10. Shell Programming and Scripting

how to rename multiple files with a single command

Hi I have following list of files at a path: 01.AR.asset 01.AR.index 01.AR.asset.vf 01.AR.asset.xv I want to rename all these files as follows: 73.AR.asset.Z 73.AR.index.Z 73.AR.asset.vf.Z 73.AR.asset.xv.Z Can any body give me a single command to acheive the above results. ... (5 Replies)
Discussion started by: tayyabq8
5 Replies
Login or Register to Ask a Question