How to strip the spaces in file names?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to strip the spaces in file names?
# 8  
Old 10-01-2010
Quote:
Originally Posted by Scrutinizer
The for loop will not work properly in this case because file names make contain whitespace and special characters. Also, you need to put double quotes around your variable references.
Try this:
Code:
find "$DIR" -type f |
while read i
do
  ffmpeg -i "$i" -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre slow -crf 22 -threads 0 "$i".mp4 &&
  qt-faststart "$i".mp4 "$i".qt.mp4 &&
  chmod 777 "$i".qt.mp4 &&
  ffmpeg  -itsoffset -4  -i "$i" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x200 "$i".jpg &&
  chmod 777 "$i".jpg &&
  mv "$i".jpg /var/www/thumbs/ &&
  rm "$i".mp4 &&
  rm "$i" &&
  mv "$i".qt.mp4 /var/www/uploads/
done

BTW chmod 777 is bad practise

thank you, it looks much simpler Smilie i learn lots today
# 9  
Old 10-01-2010
Quote:
Originally Posted by mysoogal
i try but it still can not understand, the file is Dream%20Job.mpg

the %20 is white space, how would i remove that with sed or ruby

forgive me, im new with this Smilie


this is what get

Code:
ffmpeg -i /var/www/tmp/Dream%20Job.mpg -acodec libfaac -ab 128k -ac 2  -vcodec libx264 -vpre slow -crf 22 -threads 0  /var/www/tmp/Dream%20Job.mpg.mp4

that %20 Smilie

i="`echo $i|sed 's/\[\|\]\| /_/g'`"
# 10  
Old 10-01-2010
thanks somebody in freenode #sed help me

so i figured it out like this

Code:

#!/bin/bash

 
    DIR=/var/www/tmp
 
find $DIR -type f |
while read i
do
  rename "s/%20/_/!/g;s/ /_/g" * $i && chmod 777 $i
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell command to Strip white spaces at specific location

Hello, I have a Comma separated input file with one of the sample records as below: -9223372036854477528,"834","834003325515BXNI00101012013C","5","PLAN_VALUE","PPO, General Cable","C",20130101,99991231,"A","2012-12-25-13.58.14.434000","ZPL2 ","2012-12-25-13.58.14.434000","ZPL2 ... (4 Replies)
Discussion started by: Praveenkulkarni
4 Replies

2. Shell Programming and Scripting

Finding size of files with spaces in their file names

I am running a UNIX script to get unused files and their sizes from the server. The issue is arising due to the spaces present in the filename/folder names.Due to this the du -k command doesn't work properly.But I need to calculate the size of all files including the ones which have spaces in them.... (4 Replies)
Discussion started by: INNSAV1
4 Replies

3. OS X (Apple)

Remove leading spaces from file names and folders

Hi All, I have a vexing issue with leading spaces in file names. Basically, we're moving tons of data from our ancient afp file share to Box.com and Box forbids leading spaces in files or folders. The HFS file system seems to be perfectly fine with this, but almost all other Unix file systems... (1 Reply)
Discussion started by: prometheon123
1 Replies

4. Shell Programming and Scripting

Remove spaces from start of file names

Hi, I have a directory with the following file names 01 - abc hyn 02-def 03-ghi.dir 04 - jhu.dir abc1 kil def bil The last two file names abc1 starts with one space and def starts with double space. I want these files in my directory to be renamed as ABC HYN DEF GHI.dir... (6 Replies)
Discussion started by: jacobs.smith
6 Replies

5. Shell Programming and Scripting

Opening File names with spaces inside it !- PERL

I developed a perl code..And the excerpt from it is given below... open(HANDLE,$cmp_path) ; #reading the xml file from the file path while($file_path = <HANDLE>) I have list of XML files to read from a folder. It has some spaces inside the name of the file...I used "\"... (2 Replies)
Discussion started by: gameboy87
2 Replies

6. Shell Programming and Scripting

Remove spaces between file names

Hi All, I have spaces in between file names. "Material Header.txt" "Customer Header.txt" "Vendor Header.txt" And how can I remove spaces between file names like below MaterialHeader.txt CustomerHeader.txt VendorHeader.txt Thanks Srimitta (10 Replies)
Discussion started by: srimitta
10 Replies

7. UNIX for Dummies Questions & Answers

Unable to use mimesender to send attachments with spaces in the file names / paths

Hello, I found the mimesender multiple attachment emailing shell script in the FAQ of these forums, and I have been able to use it to send multiple files, but only if they don't have spaces in their file name or path. When I attempt to send a file with spaces in it's name, enclosed... (0 Replies)
Discussion started by: rsmorra
0 Replies

8. Shell Programming and Scripting

Dealing with spaces in file names in a shell script

Hi, What's the best way to find all files under a directory - including ones with space - in order to apply a command to each of them. For instance I want get a list of files under a directory and generate a checksum for each file. Here's the csh script: #!/bin/csh set files = `find $1... (5 Replies)
Discussion started by: same1290
5 Replies

9. Shell Programming and Scripting

File names with spaces? Is it possible?

Gurus - I got one simple TXT file with long file name with blank spaces in between the words. I am trying to display that full file name, but it breaks while displaying. Could somebody shed some light here? Script ------ for i in `cat ~\temp\employee.txt` do echo $i done (5 Replies)
Discussion started by: Eric_2005
5 Replies

10. Shell Programming and Scripting

Strip leading and trailing spaces only in a shell variable with embedded spaces

I am trying to strip all leading and trailing spaces of a shell variable using either awk or sed or any other utility, however unscuccessful and need your help. echo $SH_VAR | command_line Syntax. The SH_VAR contains embedded spaces which needs to be preserved. I need only for the leading and... (6 Replies)
Discussion started by: jerardfjay
6 Replies
Login or Register to Ask a Question