I have a bunch of text files in a directory and i need to read them and extract information and keep in an excel or text file
name1_1.txt
count: 10
totalcount: 30
percentage:33
total no of a's: 20
total no of b's: 20
etc...
name2_2.txt
count: 20
totalcount: 40
percentage:50
total no of a's: 10
total no of b's: 30
etc...
etc...
output
name1 name2
count 10 20
totalcount 30 40
percentage 33 50
I want the output to keep in file called(example.txt or .csv) in the same directory. can i get help in this?
here what i tried in writing a shell script,but can't create tab separated and output to file what i needed
#$ -S /bin/bash
for sample in *.txt; do
header=$(echo ${sample} | awk '{sub(/_/," ")}1'| awk '{print $1}')
echo -en $header"\t"
done
echo -e ' \t '
echo "count"
for sample in *.txt; do
grep "count:" $sample | awk -F: $'\t''{print $2}'
done
echo "totalcount"
for sample in *.txt; do
grep "totalcount:" $sample | awk -F: $'\t''{print $2}'
done
echo "percentage"
for sample in *.txt; do
grep "percentage:" $sample | awk -F: $'\t''{print $2}'
done