Archive for April, 2019

Bash: convert word list to one line

Wednesday, April 24th, 2019
bastion@host:~$ cat pids.txt 
1111
2222
3333
4444
bastion@host:~$ echo $(cat pids.txt)
1111 2222 3333 4444

for i in `echo $(cat killpids.txt)` ; do kill -9 $i ; done

UPD: a note with alternative commands from Liviu Chircu, OpenSIPS core developer:

1.  instead of `echo $(cat pids.txt)`, a better alternative would be:
`cat pids.txt | xargs`

2.  instead of "for i in `echo $(cat pids.txt)`;  do kill -9 $i; done",
a better option would be: `cat pids.txt | xargs kill -9`