How to extract data from multiple files
1
0
Entering edit mode
9.1 years ago
pbigbig ▴ 250

Hi all,

I am doing some data extraction but got some difficulty in extracting from multiple files, I really appreciate your help in this situation:

I have many patient profile in separate folders, e.g patient1; patient2; patient3; ...

Each folder contain data files: test1; test2; test3; test4

I would like to count the number of occurrences of the string "hgc" in each test file in each patient folder and summary this values in an only file following this form:

patient1 value1 value2 value3 value4 #(each value is corresponded to a test file, from test1 to test4)
patient2 value1 value2 value3 value4
patient3 value1 value2 value3 value4
...

I was trying to fill this form manually using grep and wc command, but it would take forever if number of patient is large.

I really appreciate any help, thanks a lot!

grep • 2.0k views
ADD COMMENT
5
Entering edit mode
9.1 years ago

Something like:

for p in `ls -d patient*`
do
    echo -n $p >> some_file.txt
    for d in `ls $p/test*`
    do
        n=`grep -n hgc $d`
        echo -ne "\t$n" >> some_file.txt
    done
    echo -ne "\n" >> some_file.txt
done

That should be enough to get you started at least.

ADD COMMENT
0
Entering edit mode

Thank you very much!

ADD REPLY

Login before adding your answer.

Traffic: 2397 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6