- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: remove special character and space from file n...
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
10-24-2008 03:07 AM
10-24-2008 03:07 AM
remove special character and space from file name
I have some issue while removing special character and space from file name in hp-ux.
I have 7000 file which have special charater and space between two character in file name.
Which I remove with help of shell script.I used this command.
for file in *
do
mv "$file" `echo "$file" | sed 's/[^A-Za-z0-9_.]//g'`
done
this is working but I am getting lesser file.
I mean I have 7000 file after running this command I will get 6755 file.
So how can I get exact file after running this command.
Please help me any body.
Thanks
Dhirendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2008 04:10 AM
10-24-2008 04:10 AM
Re: remove special character and space from file name
> command I will get 6755 file.
If you have two files, one named "a b", and
one named "a b", your name-changing method
will get "ab" for both of them. You might do
better using something like:
sed 's/[^A-Za-z0-9_.]/_/g'
but that can fail in other cases.
You may need to do something smarter than
simply throwing away unwanted characters, but
my psychic powers are too weak to tell me
waht your file names look like, or how you
would like to handle the more tricky cases.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2008 04:13 AM
10-24-2008 04:13 AM
Re: remove special character and space from file name
Please provide the old and new file name.
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2008 04:44 AM
10-24-2008 04:44 AM
Re: remove special character and space from file name
> I mean I have 7000 file after running this command I will get 6755 file.
...which probably means that you are overwriting 245 of your files. You need to formulate the new file name and *test* for its presence *before* you 'mv' (rename) the old file to the new file.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2008 04:56 AM
10-24-2008 04:56 AM
Re: remove special character and space from file name
ADMIRALM-. 1089 FS-MSDS-English.pdf
ADMIRALM-. 1089 FS-MSDS_CANADA-Canadian English.pdf
ADMIRALM-. 1089 FS-MSDS_CANADA-Canadian French.pdf
ADMIRALM-. 1165 PR -- DELETE FROM MRIF DB 73106-MSDS-English.pdf
ADVANTAGEM-^Y AC1529-MSDS-English.pdf
ADVANTAGEM-^Y AC1529-MSDS_CANADA-Canadian English.pdf
ADVANTAGEM-^Y AC1529-MSDS_CANADA-Canadian French.pdf
XXTRADURA CAS-MSDS-English.pdf
XXTRADURA FLA 3766-MSDS-English.pdf
XXTRADURA FLA 3767-MSDS-English.pdf
YARMOR® 302 -- OBSOLETE PER C SHANNON 41906-MSDS-English.pdf
YARMOR® 302 -- OBSOLETE PER C SHANNON 41906-MSDS_CANADA-Canadian English.pdf
YARMOR® 302 -- OBSOLETE PER C SHANNON 41906-MSDS_CANADA-Canadian French.pdf
YARMOR® 60-SC -- OBSOLETE PER C SHANNON 33006-MSDS-English.pdf
YARMOR® 80 -- OBSOLETE PER C SHANNON 33006-MSDS-English.pdf
and after running this command again and I got 150 lesser file.
sed 's/[^A-Za-z0-9_.]/_/g'
regards
Dhirendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2008 07:20 AM
10-24-2008 07:20 AM
Re: remove special character and space from file name
You could do the suggested test, and don't do
the "mv" if the destination file exists.
Then change "_" to "__" and try again.
Repeat as needed.
Whether it makes sense to rename files in
ways where you don't know what the old name
was is another question entirely.