0

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!

3
  • Your command produces a result as "Desired Output" in your previous question here. it's unclear what you are asking here also. if you want column 17~47 to print, you don't need an array, just do awk '{n=(NR==1? 25:17);for(i=n;i<=NF;i++) print $i}' logfile if the columns are separated with Tab/Space Aug 24, 2018 at 20:25
  • The question is clear. I don't know if you're able to see the correct question, because in that case I found I wanted. But in this case I only want to order the Strings with their columns. Aug 24, 2018 at 20:32
  • @αғsнιη post your comment like answer, is the most near answer I want to solve this. Please, I want to mark like solution. Aug 24, 2018 at 20:41

1 Answer 1

2

Is that what you want?

cat thefile | tr '\t' ' '| tr -s " " | cut -d' ' -f25-46 

Please mark as the correct answer if that solve your problem

10
  • Almost done, but is still pasting the strings of other columns. Aug 24, 2018 at 19:59
  • What other columns can you try to explain more? Aug 24, 2018 at 20:02
  • Content of all columns earliest of 25. For example if I have in the column 24 a word 'dog', it will be paste in the column 25. Aug 24, 2018 at 20:03
  • Do you have columns separeted by tab? Are you saying that columns 1 to 25 are show by cut? Try the new version considering columns separated by tab. Aug 24, 2018 at 20:43
  • 1
    Please don't give up... Post the output you are getting.and what you expect Aug 24, 2018 at 20:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .