I want to filter some columns of a file, it has 46 in total. I only want to filter from the 25 until the 46, by the next way:
Desired Output:
Column25 Column26 ... Column47
Column25 Column26 ... Column47
Column25 Column26 ... Column47
I have the correct command with awk:
cat -n <(awk '{n=17;if(NR==1)n=25;for(i=n;i<=NF;i++) a[$i]++} END{for(val in a) print val,a[val]}' filelog.txt)
The command above, takes from the 25 column until the last one, in this case is the 47. It works properly, prints all the strings in all the fields I want.
But there is a problem here:
The columns I would like to print have whitespaces like the next way:
Column25 Column26 ... Column47
Column25 Column26 [...] Column47
[:space:]Column26 [:space:] Column47
[:space:][:space:] [:space:] [:space:]
Column25 [:space:] [:space:] [:space:]
The problem is: When I print all specific columns, the strings in another columns pass to the white spaces in the columns desired.
For example:
Column25 Column26 ... Column47
Column25 Stringsofcolumn12 Manystrings Stringsofcolumn21
Stringsofcolumn23 Stringsofcolumn5 ofmanycolumns Stringsofcolumn22
Column25 Stringsofcolumn16 blablabla anothermanystrings
Are any way to delete the white spaces in the columns I would like to print, to avoid this situation?
NOTE:
The strings of the columns, have the same text of the headers. example: if the column28
has content strings, the strings are column28
literally. But I guess that doesn't matter right now, only comment.
Thank you!
awk '{n=(NR==1? 25:17);for(i=n;i<=NF;i++) print $i}' logfile
if the columns are separated with Tab/Space – αғsнιη Aug 24 '18 at 20:25