checking for a space in a file name


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers checking for a space in a file name
# 1  
Old 03-01-2007
checking for a space in a file name

hi members...

another new probs...
i need to check all the zip files in the server and check for a space or "`" in the file name and if found need to remove them and form a zip file.

i tried using grep command to check for a space but with out success also when i tried checking for "`" as its a special character its not recognisable in the script .. so need to have escape sequence i suppose ..

i need help to come out of this
please help
# 2  
Old 03-01-2007
Code:
while read file
do

#Following would have the clean name without such chars
#newfile=`echo "$file" | sed "s/[ \`]//g"`

mv $file `echo "$file" | sed "s/[ \`]//g"`

done < list_of_filenames_with_such_chars

# 3  
Old 03-01-2007
Hi,
Try to use egrep as follows
ls *.zip | egrep -e '(" "|\`)'
This will find the files with space or ` in the file name.
If you want to search multiple directories try to use it with find..

Thanks
Raghu
# 4  
Old 03-01-2007
finding space in file name

hi matrix...

plz cud u explain the command

mv $file `echo "$file" | sed "s/[ \`]//g"`

also when i execute this command
we got error
unexpected EOF while looking for matching ``'

please help
# 5  
Old 03-01-2007
Quote:
Originally Posted by madhu_aqua14
hi matrix...

plz cud u explain the command

mv $file `echo "$file" | sed "s/[ \`]//g"`

also when i execute this command
we got error
unexpected EOF while looking for matching ``'

please help
Could you please post how you had executed the command, with your input, if possible ? Smilie

File with spaces and ` character are suppressed and the old file is renamed to new file
# 6  
Old 03-01-2007
checking spaces

hi matrix

here is the file name
3`_1_01_au.zip

and the code

ls *.zip | while read file
do
echo $file
echo "$file" | sed "s/[ \`]//g"
mv $file `"$file" | sed "s/[ \`]//g"`
done

error : mv: missing file argument
and unexpected EOF while looking for matching ``'
Smilie
# 7  
Old 03-01-2007
try this
Code:
mv $file $( echo "$file" | sed "s/[ \`]//g" )

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking Multiple File existance in a UNIX folder(Note: File names are all different)

HI Guys, I have some 8 files with different name and extensions. I need to check if they are present in a specific folder or not and also want that script to show me which all are not present. I can write if condition for each file but from a developer perspective , i feel that is not a good... (3 Replies)
Discussion started by: shankarpanda003
3 Replies

2. Shell Programming and Scripting

Awk: File Checking Issues with 9 multiple file

Hi, I have 9 files which are generated dynamically & if there is a some condition which doesn't meet the criteria then file is not created or is of zero size. so further i am unable to consolidate the files based on following code 1 awk -F, -v ptime="201407" 'FNR==1... (3 Replies)
Discussion started by: siramitsharma
3 Replies

3. Solaris

UNIX Checking Tape Space

Hello. My name is Alex and I am new to the UNIX environment. One of the things that I do on a daily basis is I perform backups to tape on a Sun Ultra 25. I use DAT72 tape. The tape that is currently in the tape drive has about five database backups within it already. I was just hoping... (19 Replies)
Discussion started by: daddy.torres
19 Replies

4. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

5. UNIX for Advanced & Expert Users

Checking the space for /archlog mount point script

I have the below shell script which is checking /archlog mount point space on cappire(solaris 10) server. When the space usage is above 80% it should e-mail. When i tested this script it is working as expected. #!/usr/bin/ksh export MAIL_LIST="tlr.voora@zamn.com" export ARCH_STATUS=`df -k... (1 Reply)
Discussion started by: dreams5617
1 Replies

6. Shell Programming and Scripting

Checking the space for /archlog mount point script

I have the below shell script which is checking /archlog mount point space on cappire(solaris 10) server. When the space usage is above 80% it should e-mail. When i tested this script it is working as expected. -------------------------------------------------------------------------... (0 Replies)
Discussion started by: dreams5617
0 Replies

7. Homework & Coursework Questions

Unix space checking script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Im still pretty new to this and could really use some help with this task "Write a script to check in the... (12 Replies)
Discussion started by: krolike
12 Replies

8. Shell Programming and Scripting

Script check for file, alert if not there, and continue checking until file arrives

All, Is there a way to keep checking for a file over and over again in the same script for an interval of time? Ie If { mail -user continue checking until file arrives file arrives tasks exit I don't want the script to run each time and email the user each time a file... (4 Replies)
Discussion started by: markdjones82
4 Replies

9. UNIX for Dummies Questions & Answers

Problem in checking space of mount.Please help me

Hi everyone, I am writing a script. As a part of this script, I wanted to check the space of few mounts, If the space usage percentage of the mount crosses over a certain limit then i wanted to display a warning message. The following is the command df -k | awk ' { if (($6 == "/export/temp")... (4 Replies)
Discussion started by: Sheethal
4 Replies

10. Solaris

Command used for checking space occupied by files & sub-direc's inside a mount in %?

Hi, I want to know the command which can be used for finding the % of disk space occupied by files & sub-folders inside a given mount in Sun Solaris For eg: I have /tmp/ folder when I sat df -k it will give the percentage of space used by /tmp/. Say if I want to see how much % the files &... (2 Replies)
Discussion started by: weblogicsupport
2 Replies
Login or Register to Ask a Question