How to exclude files from printed results


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to exclude files from printed results
# 1  
Old 09-18-2005
How to exclude files from printed results

Hello
I have application that part of its command I can get list of files to the stout . with the path .
like :
./blah/blah/foo.c
./blah11/blah11/foo11.c
./blah12/blah12/foo11.h

now I will like to filter this result and for instance see the "*.h" file or the "*.c" file or only the files that starts with foo
Thanks
# 2  
Old 09-18-2005
pipe through grep

if you pipe to grep -v what you dont want you will get the desired effect.

ie if you didnt want to see files called foo.c you would grep -v foo.c and get the following output:

./blah11/blah11/foo11.c
./blah12/blah12/foo11.h
# 3  
Old 09-18-2005
But if you wanted files that start with foo, can contain anything else, and end in .c or .h, then use a regular expression to grab what you want.

e.g.
Code:
my_command_that_produces_some_output | grep "/foo.*\.[ch]$"

Either way, grep is what you want.

Cheers
ZB
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl command line option '-n','-p' and multiple files: can it know a file name of a printed line?

I am looking for help in processing of those options: '-n' or '-p' I understand what they do and how to use them. But, I would like to use them with more than one file (and without any shell-loop; loading the 'perl' once.) I did try it and -n works on 2 files. Question is: - is it possible to... (6 Replies)
Discussion started by: alex_5161
6 Replies

2. Shell Programming and Scripting

How to exclude some files from the loop on the directory?

I have one question. On the directory I have many files start with DB.DAILYxxxxxxx.YYYYMMDD.HHMMSS and I have several files with other format, like LET.20170310 daily.20170310 tba.20170310 How can I exclude from my loop DB.DAILY files? I tried ls *20170310* | while read... (4 Replies)
Discussion started by: digioleg54
4 Replies

3. Shell Programming and Scripting

Exclude files in ls

Hi, I need to exlucde the files which are present in exclude.txt from a directory exlcude.txt AUZ.txt AUZ.chk NZ.txt NZ.chk tried with below code but not working ls -ltr | grep -v `cat exclude.lst` (9 Replies)
Discussion started by: rohit_shinez
9 Replies

4. Shell Programming and Scripting

Need to exclude .NFSxxx files in clear old files batch script

I am new to Shell Scripting and need some help. The following batch job has been failing for me due to the .nfsxxx files in use. I need to know how to modify the following script to exclude the .nfsxxx files so this batch job will not fail on me. I have done lots of googling and keep coming back... (2 Replies)
Discussion started by: kimberlyg2007
2 Replies

5. Shell Programming and Scripting

Recursively cat files in a directory with filename printed first.

I want to recursively cat the content of files in a directory e.g. find /etc -type f -exec cat {} \; But I want it to print the file name first and then the content. For example let's say /etc/statetab and /etc/colord.conf will be printed first then I want the output to look something like; ... (6 Replies)
Discussion started by: lewk
6 Replies

6. Ubuntu

[Solved] Using Find with an exclude/exclude file

I am familiar with using tar and exclude/include files: tar zcf backup.dirs.tgz --files-from=include.mydirs --exclude-from=exclude.mydirs --no-recursion but was wondering if I could use find in the same way. I know that you can just specify the directories to exclude but my list is... (2 Replies)
Discussion started by: metallica1973
2 Replies

7. AIX

exclude files not working

HI, I have upgraded nim master and client to TL8,SP6. Now when the mksysb backup ran from master,it is not excluding directories specified in /etc/exclude.rootvg in the client.Instead,mksysb is getting created for all the file systems in the rootvg. This problem only appeared after the TL... (3 Replies)
Discussion started by: to_bsr
3 Replies

8. UNIX for Dummies Questions & Answers

list the files but exclude the files in subdirectories

If I execute the command "ls -l /export/home/abcde/dev/proj/code/* | awk -F' ' '{print $9}' | cut -d'/' -f6-8" it will list all the files in /export/home/abcde/dev/proj/code/ directory as well as the files in subdirectories also proj/code/test.sh proj/code/test1.c proj/code/unix... (8 Replies)
Discussion started by: shyjuezy
8 Replies

9. UNIX for Advanced & Expert Users

du (exclude files)

Hi, I want to get the disk usage of a directory. But I want it to ignore a particular directory within it. Lets say I want disk usage of all files/dirs within dir1 except those that are named .snapshot Does du have the option of excluding a particular directory. (1 Reply)
Discussion started by: the_learner
1 Replies

10. UNIX for Advanced & Expert Users

lp - order of files printed

I have a shell script that is looping through a list of Postscript files to print. ls -1tr *.PS > print.lst ... PRINT_LIST=`cat print.lst` ... for DMFILE in $PRINT_LIST do lp -d $PRINTER_NAME -o legal $DMFILE ... done The files in print.lst are in the order that they should be... (2 Replies)
Discussion started by: mabrownawa
2 Replies
Login or Register to Ask a Question