Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-12-2008, 05:37 AM   #1
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.

Old 03-12-2008, 05:41 AM   #2
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.


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

All times are GMT -5. The time now is 11:00 AM.

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