-1

Good day all,

I am running below command:

netstat -an | awk '/:25/{ print  $4 }' | sed 's/:25//' | paste -sd ',' -

which produces

192.168.2.22,127.0.0.1

I would like to amend the result to something like below (to be parsed as a csv by an application)

Manuallyaddedtext 192.168.2.22,127.0.0.1

Many thanks

nu11p01n73R
  • 26,397
  • 3
  • 39
  • 52
Archie
  • 115
  • 1
  • 3
  • 10
  • 2
    It would be useful to see an example of the output of `netstat -an` - there is definitely no need to use awk, sed and paste here. – Tom Fenech Jan 28 '16 at 12:00
  • Check: http://stackoverflow.com/questions/2099471/add-a-prefix-string-to-beginning-of-each-line – Identity1 Jan 28 '16 at 12:02
  • Thanks Tom, actually I used: echo -n "Mytext " ; netstat... – Archie Jan 28 '16 at 12:43
  • 1
    It would be nicer to use `printf 'Mytext %s\n' "$(netstat -an | awk ...)"`, where the single awk command is something that I haven't told you yet, because you haven't shown me the output that needs transforming! – Tom Fenech Jan 28 '16 at 12:48
  • Not sure how to import the netstat result. The commend section skews the table format. – Archie Jan 29 '16 at 12:55

1 Answers1

-1

echo -n "Mytext " ; netstat...

Archie
  • 115
  • 1
  • 3
  • 10
  • That is a ridiculous "solution". Do what @TomFenech asked in his comments and someone will show you a reasonable way to do what you want. – Ed Morton Jan 28 '16 at 14:50