SRG041808
asked on
cat command read one file at a time
Currently I have a cat command that reads all the files in a directory, grep the data I want, then output it to a file.
Is there a way to have each file processed 1 at a time?
Below is my code and example output.
I would like the output to be
042811104531$ <--this is BEGIN:VCAL output
PRODID:-//Mozilla.org/NONS GML Mozilla Calendar V1.1//EN$ <---this is PROID: output
042811104531$ <---this is VERSION:2.0 output
042811104531$ <--this is BEGIN:VCAL output
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN$ <---this is PROID: output
042811104531$ <---this is VERSION:2.0 output
Is there a way to have each file processed 1 at a time?
Below is my code and example output.
I would like the output to be
042811104531$ <--this is BEGIN:VCAL output
PRODID:-//Mozilla.org/NONS
042811104531$ <---this is VERSION:2.0 output
042811104531$ <--this is BEGIN:VCAL output
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN$ <---this is PROID: output
042811104531$ <---this is VERSION:2.0 output
#process each file
for f in $todaydir
do
echo "Processing file(s)..."
#cat -E dfp* | egrep -i -e "VCAL|BEGIN:VEVENT|VERSION|SUMMARY|DESCRIPTION|DTSTART;TZID|DTEND;TZID|LOCATION|VEVENT|TZNAME|TRANSP:OPAQUE" > /root/Desktop/test.txt
cat -E dfp* | egrep -i -e "BEGIN:VCAL" > /root/Desktop/test.txt
cat -E dfp* | egrep -i -e "PRODID:" >> /root/Desktop/test.txt
cat -E dfp* | egrep -i -e "VERSION:2.0" >> /root/Desktop/test.txt
done
#current output below
042811104531$
042811104531$
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN$
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN$
042811104531$
042811104531$
ASKER
I think I see what we are trying to do but when I run it the script finds the correct directory and starts "processing files filenamehere" and appears to hang.
ASKER
when I comment out the egrep commands it completes
Which egrep? All of them?
I have provided $f filenames in egrep. This would hang if the filename is missing OR is an empty string. Since you see the filename, I assume you are missing the filenames.
Let me know.
I have provided $f filenames in egrep. This would hang if the filename is missing OR is an empty string. Since you see the filename, I assume you are missing the filenames.
Let me know.
ASKER
Yes, I commented out all of them and re-add them as I figure out who is the troubled line... Attached current script running output and modifications i have made to code. in the FOR statement using ls or dir does not appear to have an effect... the files that start with qfp do not need to be read.
[root@myserver Desktop]# ./reademail.sh
/data/MailArchive/archivecal/20110428
Now processing dfp3SDu5Fd009202
Now processing dfp3SE1aZ3012340
Now processing /data/MailArchive/archivecal/20110428:
egrep: /data/MailArchive/archivecal/20110428:: No such file or directory
Now processing dfp3SDu5Fd009202
Now processing dfp3SE1aZ3012340
Now processing qfp3SDu5Fd009202
Now processing qfp3SE1aZ3012340
script complete
[root@myserver Desktop]#
todaydir="/data/MailArchive/archivecal/"`eval date +%Y%m%d`
#make sure we found correct directory
echo $todaydir
#go into the directory
cd $todaydir
#process each file
FILE=/root/Desktop/test.txt
for f in $(dir dfp* $todaydir)
do
echo "Now processing "$f
cat -E dfp* |egrep -i -e "VCAL|BEGIN:VEVENT|VERSION|SUMMARY|DESCRIPTION|DTSTART;TZID|DTEND;TZID|LOCATION|VEVENT|TZNAME|TRANSP:OPAQUE" $f >> $FILE
#egrep -i -e "BEGIN:VCAL" > $f
#egrep -i -e "PRODID:" $f >> $FILE
#egrep -i -e "VERSION:2.0" $f >> $FILE
done
There is a problem in the first commented egrep
It should be
egrep -i -e "BEGIN:VCAL" $f >>$FILE
It should be
egrep -i -e "BEGIN:VCAL" $f >>$FILE
ASKER
Good call. I fixed that line... It appears somewhere that is it trying to process the folder name instead of the file name.
It is also still trying to read the qfp* files instead of the dfp* files
It is also still trying to read the qfp* files instead of the dfp* files
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did the trick thanks!
Open in new window