LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-16-2006, 08:53 AM   #1
Dr_Death_UAE
Member
 
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168

Rep: Reputation: 30
shell script:filename containing space !


Hi, i wrote a simple linux shell script to modify my nokia contacts files and add 050 befor every number in every contact file. it worked fine with all files except filenames that contain space.

for example file name "Mr John Smith.vcf", it show this error:
Quote:
sed: can't read Mr: No such file or directory
sed: can't read John: No such file or directory
sed: can't read Smith.vcf: No such file or directory
mv: target `Smith.vcf' is not a directory
Code:
#!/bin/sh

for a in *.vcf
do
sed 's/.*CELL:\([0-9]*\).*/TEL;CELL:050\1/' $a > 1$a |
 mv 1$a $a
done
any idea !

sorry for my English
 
Old 12-16-2006, 10:01 AM   #2
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
Put double quotes around the filename, such as "$a" and "l$a".
 
Old 12-16-2006, 01:06 PM   #3
Dr_Death_UAE
Member
 
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168

Original Poster
Rep: Reputation: 30
oops i tried "" with *.vcf

thanks uselpa, its working fine now.
 
Old 12-16-2006, 06:46 PM   #4
johndoe0028
Member
 
Registered: Jun 2005
Location: CA, USA
Distribution: Gentoo
Posts: 165

Rep: Reputation: 30
You can also "escape" the space character with backslashes.

this is a text file.txt
could be
this\ is\ a\ text\ file.txt
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
omitting space in shell script Fond_of_Opensource Linux - Newbie 10 11-18-2006 09:18 AM
for script: listing files which have space in filename hamish Linux - General 5 10-22-2005 09:25 AM
Space Key in Shell Script joshlamerritt Linux - General 1 02-20-2004 01:31 PM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
Changing to a directory with a space in the filename? guitargeek Linux - General 5 02-13-2003 05:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration