Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to run a program (a binary executable) inside awk?

I want to loop through rows in a text file and run ffmpeg with the field values as parameters. This is the code I tried:

awk -F, '{ffmpeg $1 -ss $2 -to $3 $4}' times.txt

and here’s the content for times.txt

TheArtofSupporting.mkv,00:11:54,00:13:33,everyone is fighting a battle.mp4

But the output is empty. Probably I just assumed that awk can run a command inside, but if this is not possible what should I do to achieve my goal. Perhaps I can output the commands into a bash file, or pipe the output by print into sh ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

awk has a system function:

awk -F, '{system("ffmpeg "$1" -ss "$2" -to "$3" "$4)}' times.txt

This, like any thing that tries to construct a shell command from possibly untrusted input, should be considered fragile.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading