Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
so i have a Q,
i run a find command to find all files that are "ASCII" and output their full path to a file.
then i run
Code:
for i in `cat all-ascii-files`; do grep -P '\d{3}-\d{3}-\d{3}' $i >> out.txt; done
but something odd happens, i will get some stdout messages that some files are not there "no such file or directory", then the cursor sits there not at a prompt (cant see prompt), but when i hit enter i get a Exit 1 status code for the above "for" statement. why?
Last edited by Linux_Kidd; 11-13-2012 at 04:34 PM.
You could try modifying the code to print the file names passed to grep and then examine all-ascii-files to see what is the name of the file causing the problem
Code:
for i in `cat all-ascii-files`; do
echo "DEBUG: i is '$i'"
grep -P '\d{3}-\d{3}-\d{3}' $i >> out.txt
done
why would a file name cause an Exit 1? if the file does not exist then the grep simply gives error to stdout "no such file or directory" and the 'for' loop continues.
i can see if the last entry in the file is a file that does not exist then grep exits with a Exit 1 code, but why do i see the command line "script" exit on stdout only when i type a key?
Last edited by Linux_Kidd; 11-13-2012 at 09:11 PM.
You could try modifying the code to print the file names passed to grep and then examine all-ascii-files to see what is the name of the file causing the problem
Code:
for i in `cat all-ascii-files`; do
echo "DEBUG: i is '$i'"
grep -P '\d{3}-\d{3}-\d{3}' $i >> out.txt
done
i did the test slightly different, i grep'd for something i knew would be no match, wc -l for input and output files are exactly the same. the Exit 1 i see must be grep failing the match when grep'ing the last $i ??
i just dont understand why i see the Exit status after hitting a key.
[1]+ Exit 1 cat all-ascii-file | while read ITEM; do
grep -P '\d{3}-\d{3}-\d{3}' "${ITEM}" >> junk.out;
done
so, it seems that the Exit 1 status code is from grep not finding anything on the last $ITEM it looks at. i grep'd a file for non-existent string and $?=1, but grep for a known match and $?=0.
but correct me if i am wrong, the reason i see the odd way job finishing when using 'for' loop is due to IFS? which IFS causes that?
thanks for the help, its be a learning session for me.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.