Sponsored Content
Top Forums UNIX for Dummies Questions & Answers List only required files in single command Post 302951848 by derekludwig on Tuesday 11th of August 2015 06:45:35 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. UNIX for Dummies Questions & Answers

List several files into one single column

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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
DIRECTORY(3)						   BSD Library Functions Manual 					      DIRECTORY(3)

NAME
opendir, fdopendir, readdir, readdir_r, telldir, seekdir, rewinddir, closedir, dirfd -- directory operations LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <dirent.h> DIR * opendir(const char *filename); DIR * fdopendir(int fd); struct dirent * readdir(DIR *dirp); int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result); long telldir(DIR *dirp); void seekdir(DIR *dirp, long loc); void rewinddir(DIR *dirp); int closedir(DIR *dirp); int dirfd(DIR *dirp); DESCRIPTION
The opendir() function opens the directory named by filename, associates a directory stream with it and returns a pointer to be used to iden- tify the directory stream in subsequent operations. The pointer NULL is returned if filename cannot be accessed, or if it cannot malloc(3) enough memory to hold the whole thing, and sets the global variable errno to indicate the error. The fdopendir() function is equivalent to the opendir() function except that the directory is specified by a file descriptor fd rather than by a name. Upon successful return from fdopendir(), the file descriptor is under the control of the system, and if any attempt is made to close the file descriptor, or to modify the state of the associated description other than by means of closedir(), readdir(), readdir_r(), or rewinddir(), the behavior is undefined. Upon calling closedir() the file descriptor is closed. The FD_CLOEXEC flag is set on the file descriptor by a successful call to fdopendir(). The readdir() function returns a pointer to the next directory entry. It returns NULL upon reaching the end of the directory or on error. In the event of an error, errno may be set to any of the values documented for the getdirentries(2) system call. Note that the order of the directory entries vended by readdir() is not specified. Some filesystems may return entries in lexicographic sort order and others may not. The readdir_r() function provides the same functionality as readdir(), but the caller must provide a directory entry buffer to store the results in. If the read succeeds, result is pointed at the entry; upon reaching the end of the directory result is set to NULL. The readdir_r() function returns 0 on success or an error number to indicate failure. The telldir() function returns the current location associated with the named directory stream. Values returned by telldir() are good only for the lifetime of the DIR pointer, dirp, from which they are derived. If the directory is closed and then reopened, prior values returned by telldir() will no longer be valid. The seekdir() function sets the position of the next readdir() operation on the directory stream. The new position reverts to the one asso- ciated with the directory stream when the telldir() operation was performed. The rewinddir() function resets the position of the named directory stream to the beginning of the directory. The closedir() function closes the named directory stream and frees the structure associated with the dirp pointer, returning 0 on success. On failure, -1 is returned and the global variable errno is set to indicate the error. The dirfd() function returns the integer file descriptor associated with the named directory stream, see open(2). On failure, -1 is returned and the global variable errno is set to indicate the error. Sample code which searches a directory for entry ``name'' is: dirp = opendir("."); if (dirp == NULL) return (ERROR); len = strlen(name); while ((dp = readdir(dirp)) != NULL) { if (dp->d_namlen == len && strcmp(dp->d_name, name) == 0) { (void)closedir(dirp); return (FOUND); } } (void)closedir(dirp); return (NOT_FOUND); SEE ALSO
close(2), lseek(2), open(2), read(2), dir(5) HISTORY
The opendir(), readdir(), telldir(), seekdir(), rewinddir(), closedir(), and dirfd() functions appeared in 4.2BSD. The fdopendir() function appeared in FreeBSD 8.0. BSD
April 16, 2008 BSD
All times are GMT -4. The time now is 07:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy