0

I am using the command below to output a list of IP addresses on the one line with the statement "working IP" after each IP

cat eciremoteExec1.txt | sort | uniq -c | awk -F " " '{print $3}' | sed 's/$/ working IP/'  | sed -e '0,/ working IP/ s/ working IP//' | sed '$ d' | paste -s -d ' ' | sed 's/working IP$//'

The output looks like this:

147.123.41.112 working IP 129.138.70.113 working IP 173.230.45.54 working 
IP 133.218.250.56 working IP 136.203.152.128 working IP 117.22.29.254 
working IP 117.3.11.111 working IP 127.59.131.236 

I piped it into sed multiple times to get it to look as I wanted. Is there a better approach than using sed multiple times?

  • 3
    Advise what the file contains... post some data of file. – George Vasiliou Dec 17 '16 at 15:40
  • 2
    You can run multiple sed operations in a single sed call. – Grzegorz Oledzki Dec 17 '16 at 18:20
0

it's probably possible to combine the first three sed calls like this

cat eciremoteExec1.txt | sort | uniq -c | awk -F " " '{print $3}' |
   sed 's/$/ working IP/;s/ working IP//; $ d' | paste -s -d ' ' |
   sed 's/working IP$//'

but it's hard to say without knowing what inputs are legal and what output is desired.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.