I am a total novice to coding, but am wondering the easiest way to generate a table from grep count data.
My grep count output file looks like this:
AAR34355.1
./006D_id70.m8:0
./20D_id70.m8:0
./28D_id70.m8:0
AAR38850.1
./006D_id70.m8:0
./20D_id70.m8:2
./28D_id70.m8:4
A13520.1
./006D_id70.m8:0
./20D_id70.m8:0
./28D_id70.m8:0
I need an output to look more like this:
./006D_id70.m8 ./20D_id70.m8 ./28D_id70.m8
AAR34355.1 0 0 0
AAR38850.1 0 2 4
A13520.1 0 0 0
or at least a delimited equivalent.
Forgive my description, as I am pretty new to this.
Is there a relatively simple way of formatting the data this way?
Select a cell within your data. Select Home > Format as Table. Choose a style for your table. In the Format as Table dialog box, set your cell range.
Formatting your range as a table tells Excel that those rows and columns are all related, and that there are headers in the first row. And by doing this, your range now has meaning. Excel understands it better. And with that, lots of additional benefits are born.
When you use Format as Table, Excel automatically converts your data range to a table. If you don't want to work with your data in a table, you can convert the table back to a regular range while keeping the table style formatting that you applied.
You can do that all in awk, no need to reshape grep's output. Assuming patterns to be searched for are listed in a file named patterns
, and files to be searched in are file1
, file2
, and file3
; copy and save the following code block into a file named tst.awk
,
NR == FNR {
pat[NR] = $0
next
}
FNR == 1 {
fil[c++] = FILENAME
}
{
for (i in pat)
if ($0 ~ pat[i])
mat[FILENAME, pat[i]]++
}
END {
for (i in fil)
printf "\t%s", fil[i]
print ""
for (i in pat) {
printf "%s", pat[i]
for (j in fil)
printf "\t%d", mat[fil[j], pat[i]]
print ""
}
}
and run
awk -f tst.awk patterns file1 file2 file3
Demo:
$ seq 5 > file1
$ seq 3 7 > file2
$ seq 5 9 > file3
$ seq 3 2 7 > patterns
$ awk -f tst.awk patterns file1 file2 file3
file1 file2 file3
3 1 1 0
5 1 1 1
7 0 1 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With