It is currently Fri May 25, 2018 12:51 pm

Bash script read specifc value from files of an entire folde

All times are UTC - 6 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Fri Mar 28, 2014 8:12 am   

Joined: Fri Mar 28, 2014 8:11 am
Posts: 1
I heva a problem creating a script that read specifc value from all the files of an entire folder

I have a number of email files into a directory and i need to extrect from each file 2 specific values.
After that i have to put them into a new file that looks like that:
To: value1


This is what i want to do, but i don't know how to create the script:

ls -l | awk '{print $9 }' >tmpfile - i am putting the name of the files into a temp file
date=`date +"%T"` - used for the name of a file
var1=`cat tmpfile | grep "To: 0" | awk '{print $2 }' | cut -b -10 ` - the first specific value from file(phone number)
var2=cat file | grep Subject | awk '{print $2$3$4$5$6$7$8$9$10 }' - the second specific value from file(subject)
echo "To: 4"$var1"" > sms-$date - put the first value in a new file on the first row
echo ""$var2"" >>sms-$date put the second value in the same file on the second row
and do the same for every file in the directory

I tried using while and for functions but i couldn't finalize the script

Thank You

 PostPosted: Fri Mar 28, 2014 4:09 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 643
same question, same answer:

to loop over files in a directory, use `for' statement and pathname expansion:
for file in directory/*; do : stuff with "$file"; done

parsing `ls' is useless, tricky, better not use it in scripts.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: Bing [Bot] and 6 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group