awk remote multiple hosts print remote hostname and output

Hi all,
i'm trying to gether multiple pattern on remote hosts, and trying to print hostname and the pattern,

ssh remoteserver1 -C 'hostname 2>&1;cat /var/log/server1.log | awk -F ";" '"'"'{ print " "$2" "$5}'"'"'| sort | uniq -c | sort -g -r '

The output is the following,

 remoteserver1
  5272  3 service Hit with key 
   824  4 service Hit with key
   641  1000 service Hit with key
   264  1000 service Hit with key
    91  1000 service Hit with key
    76  1 service Hit with key
     4  7 service Hit with key
     1  1 service Hit with key

I need to output the following format

remoteserver1
			5272		3	service Hit with key
			824 		4	service Hit with key
			641		1000	service Hit with key
			264		1000	service Hit with key
			91		1000	service Hit with key
			76		1	service Hit with key
			4		7	service Hit with key
			1		1	service Hit with key

Could you please support on this?

Try printing one or two <TAB> chars in lieu of the single space character, or set awk 's OFS to <TAB> .

EDIT: You might also try

ssh remoteserver1 -C 'hostname 2>&1;  awk -F ";" '{CNT[$4 OFS $5]++} END {for (c in CNT) print "", CNT[c], c | "sort -gr"}' OFS="\t" /var/log/server1.log'

Thank for input RudiC,
on this i'm getting

-bash: syntax error near unexpected token `('

Any idea?

Hmmm - quoting seems to be a problem - I didn't test the final version when having exchanged my parameters with yours. What is the -C option meant for?

Try

ssh remoteserver1 'hostname 2>&1;  awk -F ";" '"'"'{CNT[$4$2 OFS $5]++} END {for (c in CNT) print "", CNT[c], c | "sort -gr"}'"'"' OFS="\t" /var/log/server1.log'

Hi RudiC,
the -C as per ssh manual stands for

     -C      Requests compression of all data (including stdin, stdout, stderr, and data for forwarded X11, TCP and UNIX-domain connections).  The compression algorithm is the
             same used by gzip(1), and the �level� can be controlled by the CompressionLevel option for protocol version 1.  Compression is desirable on modem lines and other
             slow connections, but will only slow down things on fast networks.  The default value can be set on a host-by-host basis in the configuration files; see the
             Compression option.

The suggested command is printing tha same output as the per my request without tabing the hostname, any idea buddy?

The tabbing works when I test it. You may want to play around with OFS, and printed (dummy) fields. (I used $4 for my test; change it to $2 for yor case...)

Are you on a slow modem? If not, -C is counterproductive...

Yes the tabbing works but i need an empty collumn down the hostname,

as i seem a bit difficutt what do you think, can i print the hostname inside awk, so it woud be like this

ssh $i 'cat /var/log/server1.log | awk -F ";" '"'"'{print ","$2","$5",""$i"}'"'"'| sort | uniq -c | sort -g -r '

is this feasible?

I don't understand what you get and what you're after, and where and how they disagree.

My awk proposal prints a <TAB> char in front of every line, and thus has an "empty first column" if the field separator is <TAB>. Your uniq -c approach will print the count as the first field; additional measures have to be taken to prefix a field separator.
Why don't you print the remote server name just outside the ssh line, prefixing it to the entire output?

Hi RudiC,
finally i switched to this,

awk -F ";" -v var=$(hostname) '"'"'{print","$2","$5","var}

and this works perfectlty for what i need,
thank a lot for the support.

Moderator comments were removed during original forum migration.