- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- rename files with blanks
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2005 02:27 AM
08-23-2005 02:27 AM
i have a bunch full of files which are named like this:
123 456 789.txt between each block a blank.
i`d like to rename them to 123456789.txt
I tried to ls them in a txt-file, but if i use a loop it can`t find the files because of the separation in the filename
I wrote a loop like this:
for i in `ls *`
do
echo $i
done
the output is shown
123
456
789.txt
The same if i use quotes on the filename "123 456 789.txt"
the ouptup is the same like above
for i in `ls "*"`
do
echo $i
done
123
456
789.txt
Please , down on my knees ;-) , HELP
I have to rename around 2500 files
THanks for all your comments.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2005 02:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2005 02:33 AM
08-23-2005 02:33 AM
Re: rename files with blanks
ls -1 | while read filename
do
newname=`echo $filename | sed -e "1,1s/\ //g"`
mv "$filename" "$newname"
done
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2005 02:33 AM
08-23-2005 02:33 AM
Re: rename files with blanks
try a simple sloution as
ls |while read a b c
do
echo $a$b$c
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2005 02:53 AM
08-23-2005 02:53 AM
Re: rename files with blanks
thanks i worked .
Still on my knees , head on the floor.
Points are on the way
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2005 02:54 AM
08-23-2005 02:54 AM
Re: rename files with blanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2005 03:23 AM
08-23-2005 03:23 AM
Re: rename files with blanks
#!/usr/bin/sh
typeset -i ${STAT}=0
typeset F=''
typeset F2=''
ls *.txt | while read F
do
echo "File: \"${F}\" \c"
F2=$(echo "${F}" | tr -d ' ')
if [[ "${F}" != "${F2}" ]]
then
if [[ -e "${F2}" ]]
then
echo "File ${F2} exists; cannot mv." >&2
else
echo "-> ${F2}\c"
mv "${F}" "${F2}"
STAT=${?}
if [[ ${STAT} -ne 0 ]]
then
echo "Mv failed; status ${STAT}" >&2
break
fi
fi
fi
echo
done
exit {$STAT}