LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-12-2008, 04:37 AM   #1
yeoheric
LQ Newbie
 
Registered: Mar 2008
Posts: 1

Rep: Reputation: 0
Script to change weird filenames


Hi all,

I have a Linux server (Gentoo) that receives input from users' systems.

For each input, a small text file is created based on the request e.g. REQ_2355.20080313.DAT). The 2355 is a category and REQ is a key meaning REQUEST.

It works fine until users miskey in Chinese or other weird chars; the filenames would be something like ???REQ_????2344.20080313????.DAT or __---REQ---.DAT.

I would like to have a script that detects such weird names and rename the files to maybe archive1.DAT, archive2.DAT etc. (if there are more than these weird filenames).

Also I have come across filenames that begin with a hyphen ('). These files I find it even to rename manually.

Please assist.

While all these can be renamed manually, I have been losing sleep (a lot of these things seem to happen in the wee hours).

Thanks in advance.

Eric
 
Old 03-12-2008, 04:41 AM   #2
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
Are you looking for such a script in bash or perl or ...? There are many options for this; one you may be interested in is 'sed' which is a program that replaces characters, words, whole paragraphs even, depending on what you tell it to do.

You should look up "regular expressions" while you're at it -- that is the language that sed (and grep, and many other invaluable tools) use to help understand exactly what you want it to find.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
script to change multiple filenames in a directory jeffreybluml Linux - Newbie 8 12-06-2006 01:46 AM
shell script - truncating filenames mr_scary Programming 3 09-04-2006 02:50 PM
need help with script to remove all metachars from filenames BrianK Programming 5 08-20-2005 11:10 PM
sftp with filenames and weird characters Nevion Linux - Software 1 05-28-2004 05:29 AM
Changing multiple filenames with a script brecki Linux - Newbie 8 01-30-2004 03:10 PM


All times are GMT -5. The time now is 12:50 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration