Home > Enterprise >  Why is cut not matching any delimiters?
Why is cut not matching any delimiters?

Time:02-14

The following is not working properly, cut is not separating at the dot but {} definitely contains a dot in the file name. find . -type f -exec echo ffmpeg -i {} -vcodec copy -acodec copy $(echo {} | cut -d "." -s -f 1).mp4 \;

CodePudding user response:

Bash performs command substitution before the command is run, you have to put in single quotes to work. The command you want to run is complex enough to call it with a separate instance of sh like that:

find . -type f -exec sh -c 'echo ffmpeg -i "$1" -vcodec copy -acodec copy $(echo "$1" | sed "s,^\./,," | cut -d "." -s -f 1).mp4' sh {} \;

For example, if the directory in which you want to run the command looked like that:

$ tree
.
├── dir
│   └── file_something.avi
├── file_a.avi
├── file_b.avi
├── file_c.avi
└── find.sh

1 directory, 5 files

it would return:

ffmpeg -i ./file_c.avi -vcodec copy -acodec copy file_c.mp4
ffmpeg -i ./find.sh -vcodec copy -acodec copy find.mp4
ffmpeg -i ./file_b.avi -vcodec copy -acodec copy file_b.mp4
ffmpeg -i ./file_a.avi -vcodec copy -acodec copy file_a.mp4
ffmpeg -i ./dir/file_something.avi -vcodec copy -acodec copy dir/file_something.mp4
  • Related