Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass a filename found in awk into vim command

Forever (a process manager for nodejs) gives new random logs each time you restart it.

I'm able to get the log filename with this command:

$ forever list | grep coffee | awk '{print $8}'
/home/vagrant/.forever/ZZRW.log

I'd like to be able to pass this filename into a vim command, so vim ends up executing:

vim /home/vagrant/.forever/ZZRW.log

And I'd like to alias this in my .bash_profile to be something like:

alias vimforeverlog="vim ???? forever list | grep coffee | awk '{print $8}'"

Any ideas? I feel like I'm just missing a basic feature of pipes.

like image 690
Civilian Avatar asked Dec 02 '25 10:12

Civilian


2 Answers

vim $(forever list | grep coffee | awk '{print $8}')

should do the job, same as opening result from find in vim.

like image 111
Kent Avatar answered Dec 05 '25 11:12

Kent


forever list | grep coffee | awk '{print $8}' | xargs vim

xargs takes the output of the last command and appends it to the command line

like image 37
theycallhimtom Avatar answered Dec 05 '25 11:12

theycallhimtom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!