Bash script read specific value from files of an entire folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script read specific value from files of an entire folder
# 1  
Old 03-28-2014
Bash script read specific value from files of an entire folder

Hello,
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:
Code:
To: value1

value2

This is what i want to do, but i don't know how to create the script:
Code:
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

Last edited by Scott; 03-28-2014 at 11:25 AM.. Reason: Please use code tags
# 2  
Old 03-28-2014
If you provide sample input and sample output it will be much more easy to understand.
For e.g. are the email and subject in each file, on the same line?

Does every email have a subject? so on. So some input and output sample will be very useful to resolve it.

Here is roughly how you want the outermost loop to be
Code:
ls -1|while read a;do

done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simply Bash Script to Confirm that there are 2 Files in Same Folder

Im looking for 2 Files -> *.WAV and *.wav with find . -name 'unavail.wav' -o -name 'unavail.WAV' I need to list the Folders that contains these 2 Files? Thx in advance (13 Replies)
Discussion started by: valdez
13 Replies

2. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

3. Shell Programming and Scripting

I want to read the content of a specific folder

Why does not work a cd in a shell schript file. How do you get to run it? I use these code: #!/bin/sh cd workspace array=($(ls -d */)) echo ${array} But it doesn't change to workspace editby bakunin: please user CODE-tags as required by the rules. Thank you. (12 Replies)
Discussion started by: Linuxmann
12 Replies

4. Shell Programming and Scripting

Replace character in files of entire folder? sed? or what?

Hello, I do have several files in one folder each file contains measurement data. for each file I would like to replace the character "," by "." ? How can I do this and how can I do this for each file at once? E.G. data_1.dat, data_x.dat (original version) data_1out.dat, data_x_out.dat... (10 Replies)
Discussion started by: rollinator
10 Replies

5. Shell Programming and Scripting

Bash script to sort files into folder according to a string in the filename

Hi all. I am very new to linux scripting and i have a task i can only solve with a script. I need to sort files base on the date string in their filenames and create a folder using the same date string then move the files to their respective folders. Scenario: Folder Path:... (1 Reply)
Discussion started by: ace47
1 Replies

6. Shell Programming and Scripting

URGENT!!! bash script to sort files into folder according to a string in the filename

Hi all. I am very new to linux scripting and i have a task i can only solve with a script. I need to sort files base on the date string in their filenames and create a folder using the same date string then move the files to their respective folders. Scenario: Folder Path:... (1 Reply)
Discussion started by: ace47
1 Replies

7. UNIX for Dummies Questions & Answers

Bash script to rename all files within a folder...

Hi. I don't have any experience with making scripts in bash. I need a simple script to rename all files in a folder to the format file1.avi, file2.avi, file3.avi, and so on..... Please note that the original files have different filenames and different extensions. But they all need to be... (2 Replies)
Discussion started by: dranzer
2 Replies

8. Shell Programming and Scripting

Script required to extract a specific snippet from the entire file.

Hi, I have a file with the following structure. XXXXX........... YYYYY........... ................. .................. ZZZZZZ...... qwerty_start.............. .................. ................. .................. querty_end................ .............................. (1 Reply)
Discussion started by: abinash
1 Replies

9. UNIX and Linux Applications

read files from folder and then call another script

Hi, I am new to the Unix shell scripting world. It would be great if some body can help me with my requirement 1) Script (say script1.sh) which will take set of files from one folder (say input folder). 2) Take the first file from the folder and execute another script (script2.sh).Pass 2... (1 Reply)
Discussion started by: girishnn
1 Replies

10. Shell Programming and Scripting

read files from folder and then call another script

Hi, I am new to the Unix shell scripting world. It would be great if some body can help me with my requirement 1) Script (say script1.sh) which will take set of files from one folder (say input folder). 2) Take the first file from the folder and execute another script (script2.sh).Pass 2... (3 Replies)
Discussion started by: girishnn
3 Replies
Login or Register to Ask a Question