Sponsored Content
Top Forums Shell Programming and Scripting basename not working as expected from find -exec Post 302631855 by jelloir on Saturday 28th of April 2012 07:24:21 AM
Old 04-28-2012
basename not working as expected from find -exec

I have the following files in a directory

Code:
> ls -1 /tmp/test/dir/
file with spaces 1.ogg
file with spaces 2.ogg

I am running the following to echo the filenames but alter the file extension on the files to .mp3 instead of .ogg ( I am going to run ffmpeg against the files ultimately, but keeping the example simple for the sake of the thread).

Code:
find /tmp/test/ -type f -name "*.ogg" -exec echo {} "$(basename {} .ogg).mp3" \;

I expect the output to be:

Code:
/tmp/test/dir/file with spaces 2.ogg /tmp/test/dir/file with spaces 2.mp3
/tmp/test/dir/file with spaces 1.ogg /tmp/test/dir/file with spaces 1.mp3

But instead it fails to remove the .ogg and I end up with:

Code:
/tmp/test/dir/file with spaces 2.ogg /tmp/test/dir/file with spaces 2.ogg.mp3
/tmp/test/dir/file with spaces 1.ogg /tmp/test/dir/file with spaces 1.ogg.mp3

* Note the ".ogg.mp3" extension *

A basic echo works as expected:

Code:
> echo $(basename /tmp/test/dir/file\ with\ spaces\ 1.ogg .ogg).mp3
file with spaces 1.mp3

I can only assume this has something to do with the space between {} and .ogg in the confines of find.

How can I run this so it produces the desired filename?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

which not working as expected

Hello. Consider the following magic words: # ls `which adduser` ls: /usr/sbin/adduser: No such file or directory # Hmmm... Then: # ls /usr/sbin/adduser /usr/sbin/adduser # Now what? Unforunately this little sniippet is used in my debian woody server's mysql pre install script.... (2 Replies)
Discussion started by: osee
2 Replies

2. UNIX for Dummies Questions & Answers

Find command not working as expected

I have a script with a find command using xargs to copy the files found to another directory. The find command is finding the appropriate file, but it's not copying. I've checked permissions, and those are all O.K., so I'm not sure what I'm missing. Any help is greatly appreciated. This is... (2 Replies)
Discussion started by: mpflug
2 Replies

3. Shell Programming and Scripting

Find cmd not working as expected

Hi, i wan to search the file starting with Admin into the directory Output. I am running below command: find /appl/Output -name "Admin*" -prune but this command is going into the sub directories present under output. I do not want to search under sub directories. Any help will be highly... (6 Replies)
Discussion started by: Vishal123
6 Replies

4. Shell Programming and Scripting

Using find command with awk or basename

Hi, I am using the following command to extract any log files that are older than 3 days using the following command. find DIR/LOGDIR -type f -mtime +3 |grep LOG > log_list.out The results are DIR/LOGDIR/1.LOG DIR/LOGDIR/2.LOG DIR/LOGDIR/3.LOG DIR/LOGDIR/4.LOG How do inculde (basename... (4 Replies)
Discussion started by: sam_78_nyc
4 Replies

5. UNIX for Dummies Questions & Answers

Redirection not working as expected

Portion of my script below : if ; then NUMBEROFFEILDS=`cat ${BASE_SCRIPT_LOC}/standardfilecleanup.lst|grep -w ${db_file_path}|awk -F: '{print NF}'` COUNT=4 while ; do awk_var="$"`echo $COUNT` file_name1=`cat ${BASE_SCRIPT_LOC}/standardfilecleanup.lst|grep -w... (1 Reply)
Discussion started by: findprakash
1 Replies

6. Shell Programming and Scripting

Why this is not working in expected way?

total=0 seq 1 5 | while read i ; do total=$(($total+$i)) echo $total done echo $totalThis outputs: 1 3 6 10 15 0whereas I am expecting: 1 3 6 10 15 15My bash version: (4 Replies)
Discussion started by: meharo
4 Replies

7. Red Hat

/usr/bin/find && -exec /bin/rm never work as expected

hi there, Would you able to advise that why the syntax or statement below couldn't work as expected ? /usr/bin/find /backup -name "*tar*" -mtime +2 -exec /bin/rm -f {} \; 1> /dev/null 2>&1 In fact, I was initially located it as in crontab job, but it doesn't work at all. So, I was... (9 Replies)
Discussion started by: rauphelhunter
9 Replies

8. UNIX for Dummies Questions & Answers

-atime not working as expected

I need to sort through a volume that contains video files by access time and delete files that have not been accessed over x days. I have to use the access time as video files are originals that do not get modified, just read Testing commands on a local test folder... $ date Wed Sep 28... (10 Replies)
Discussion started by: canon273
10 Replies

9. Shell Programming and Scripting

Script not working as expected

Hi, I have prepared a script and trying to execute it but not getting expected output. Could you please help and advise what is going wrong. "If else" part in below script is not working basically. I am running it on HP-UX. for i in slpd puma sfmdb do echo "******\t$i\t*******" echo... (10 Replies)
Discussion started by: sv0081493
10 Replies

10. UNIX for Advanced & Expert Users

Manipulate files with find and fuser not working as expected on SunOs

Greetings, For housekeeping, I use the following command: find /some/path -type f -name "*log*" ! -exec fuser -s "{}" 2>/dev/null \; -exec ls -lh {} \; It finds all log files not currently in use by a process and manipulates them. This command always works on linux and redhat machines,... (2 Replies)
Discussion started by: dampio
2 Replies
LIBVALHALLA-TEST(1)					      General Commands Manual					       LIBVALHALLA-TEST(1)

NAME
libvalhalla-test - a test media indexing utility which uses libvalhalla SYNOPSIS
libvalhalla-test [options ...] paths ... DESCRIPTION
This manual page documents briefly the libvalhalla-test command. libvalhalla-test is a command-line media indexing tool which uses libvalhalla. It is mainly used to test and exercise libvalhalla capabili- ties. OPTIONS
-h --help this help -v --verbose increase verbosity -l --loop number of loops -t --timewait time to wait between loops [sec] -e --delay delay before the scanning begins [sec] -m --timelimit time limit [ms] for the scanning -a --priority priority for the threads -d --database path for the database -f --download path for the downloader destination -c --commit-int commits interval -p --parser number of parsers -n --decrap enable decrapifier (for title metadata) -k --keyword keyword for the decrapifier -s --suffix file suffix (extension) -g --grabber grabber to be used Example: libvalhalla-test -l 2 -t 5 -d ./mydb.db -p 1 -a 15 -s ogg -s mp3 /home/foobar/music Default values are: loop=1, timewait=0, database=./valhalla.db, commit-int=128, parser=2, priority=19, suffix=flac,m4a,mp3,ogg, wav,wma,avi,mkv,mov,mpg,wmv, bmp,gif,jpeg,jpg,png,tga,tif,tiff AUTHOR
libvalhalla was written by Mathieu Schroeter <mathieu.schroeter@gamesover.ch>, Benjamin Zores <ben@geexbox.org>, Fabien Brisset <fbris- set@gmail.com> and Davide Cavalca <davide@geexbox.org>. This manual page was written by Davide Cavalca <davide@geexbox.org>, for the Debian project (but may be used by others). 10/12/2009 LIBVALHALLA-TEST(1)
All times are GMT -4. The time now is 08:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy