Results 1 to 5 of 5
I have a folder which includes bunch of folders each having data files in them. [ Folder A has F1, F2 F3 ..... F1000 folders in it, and F1, F2, ...
- 03-17-2011 #1Just Joined!
- Join Date
- Mar 2011
- Posts
- 3
reading data from multiple files.
I have a folder which includes bunch of folders each having data files in them. [ Folder A has F1, F2 F3 ..... F1000 folders in it, and F1, F2, F3 ... each has about 10 different files named FILE 1, FILE2, FILE3 .... in them.
I am interested in File 1 of each Folder, because that contains the data I need in it. More specifically, that File1 s have a line "ANSWER=..." in them, and i need to get that value of the ANSWER from each file. So doing it by hand is so hard, so I need to write a script that will scan all folders and give me a list of values of eache ANSWERs.
Any suggestions, where shoud I start?
- 03-17-2011 #2This assumes, that the value is in the second field, for = as a delimiter.Code:
find A -type f -name "FILE1" -print0 | while read -r -d '' WORKFILE; do grep "ANSWER=" ${WORKFILE}|cut -d "=" -f2 ; done
If (and only if) the directory structure is static,
then you could create a list of the files once and feed that to grep in a for loop.
Doesnt make too much sense to parallize that, unless the directories are on different spindles.You must always face the curtain with a bow.
- 03-17-2011 #3Just Joined!
- Join Date
- Mar 2011
- Posts
- 3
thank you for the answer, however i couldn't get it work. it gives the error: "Illegal option -d"
To be more precise, let me rephrase my problem. In folder A I have subfolders named: 1.11, 1.12, 1.13 etc... And in each subfolder, i have a file named OSX. And in each OSX there is a line "ANSWER=1212" (some number). I need to obtain those numbers from each subfolder of A.
- 03-17-2011 #4
The error you get is related to a "bash-ism" I used.
It seems, your shell´s "read" doesnt know -d
You have at least two options:
1) start a bash, then that line from above.
2) use this line below. Should be safe enough for filenames without any special chars, like you have:
Code:find A -type f -name "OSX" | while read WORKFILE; do grep "ANSWER=" ${WORKFILE}|cut -d "=" -f2 ; doneYou must always face the curtain with a bow.
- 03-17-2011 #5Just Joined!
- Join Date
- Mar 2011
- Posts
- 3
thank you, the second line worked fine


Reply With Quote