Automatically correct a File Name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automatically correct a File Name
# 1  
Old 05-06-2015
Automatically correct a File Name

Hi All

Need a help to understand how one can automatically correct a file name using a shell script even if it is in a completely different format...

Ex : adv_OK_0215_mem_rules_firing.txt / advex_0215_OK_me_rule_fire.txt (or in any other format as above)

to : advext_OK_2015_mem_rule_firings.txt (Final Name)

Last edited by rbatte1; 05-07-2015 at 01:28 PM.. Reason: Added ICODE tags
# 2  
Old 05-06-2015
You need to depict an algorithm how to convert all the possible corrupt elements into their final forms. What corrupt elements can occur?
# 3  
Old 05-06-2015
Hi, chatwithsaurav.

A Google search for algorithm for spelling correction produces more than 0.3 million hits.

A Google search for algorithm for language translation produces 26 million hits.

A Google search for algorithm for string substitution produces about 0.6 million hits.

A Google search for algorithm for string substitution table produces about 5 million hits.

Best wishes ... cheers, drl
# 4  
Old 05-07-2015
Hi RudiC

Many corrupt elements can occur but the script should automatically correct it to the final name. I actually need that algorithm Smilie

Regards
Saurabh
# 5  
Old 05-07-2015
Note that I will seriously doubt your judgement if you run either of these scripts.

With the information you have provided:
Code:
for i in *_*_*_*_*_*.txt
do     mv "$i" advext_OK_2015_mem_rule_firings.txt
done

or, if the number of underscores or the .txt could also be corrupted, you could simplify this to just:
Code:
for i in *
do      [ -f "$i" ] && mv "$i" advext_OK_2015_mem_rule_firings.txt

Of course either of these might match several files and destroy all but one of them, but if you can't be any more specific about what corruption can occur, that is the best we can do for you.
This User Gave Thanks to Don Cragun For This Post:
# 6  
Old 05-07-2015
Hi Don

Thanks for your solution. Well normally the user who puts the file in a predefined directory makes spellings mistakes as close to the examples which I have shared. Assuming that the "file name sequence" remains same (i.e advext_OK_0215_mem_rule_firings.txt) he/she makes mistakes like : "ad" instead of "advext" or "firng" instead of "firings" or "me/m" instead of "mem". The script will identify each "word" and correct it if its wrong. He/she can give two or more underscores and even no underscores as well.
# 7  
Old 05-07-2015
I'd propose you run a validity check on the users' input, then, and to avoid a file rename based on guesses (at best).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

LS command does not list the correct file

Hi, I am logged into as root & inside the home directory of another user. ls -a # ls -laq total 44 drwx------ 4 user1 adm 4096 Nov 23 05:10 . drwxr-xr-x. 12 root root 4096 Nov 22 13:05 .. -rw-r--r-- 1 user1 adm 18 Nov 22 13:05 .bash_logout -rw-r--r-- 1 user1 adm 193 Nov... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

Extract the correct format of file Name

All, Objective : Extract the correct format of a file name. Please share the script command which will extract the correct format of the file after untarring. Example : If the file is of .csv format then extract filename.csv if the file is having .CSV then extract the same.CSV if the file... (1 Reply)
Discussion started by: Mahesh G
1 Replies

3. UNIX for Dummies Questions & Answers

After Ftp'ing file to destination how to check the file if it is in correct ASCII and not corrupted

Hi Folks, While transferring file from FTP software like Filezilla the files gets corrupted. Is there any way I can check if the recently transferred file is in ASCII and not corrupted. I have tried using file -i filename command which does tell if the file character set is ASCII or binary... (6 Replies)
Discussion started by: Khan28
6 Replies

4. Shell Programming and Scripting

Opening a file in vi and automatically save and quit this file using shell script

Hi friends, In my shell script, I want to open a file using vi editor. After opening the file in vi, I want to save and quit this file automatically.... all through shell script. the code segment is: ------------------------------------------------------------ cd ~/netfpga/projects/scone/sw/... (2 Replies)
Discussion started by: sachinteotia
2 Replies

5. UNIX for Advanced & Expert Users

Not getting correct uptime in messages file

The following notice I am getting in /var/adm/messages file Dec 9 06:17:24 hostname lw8: Main, up 476 days 04:42:23, Memory 9,742,808 Dec 9 10:17:25 hostname lw8: Main, up 476 days 08:42:23, Memory 10,179,864 But my actual uptime is :: 11:55am up 25 day(s), 10:38, 3 users, ... (5 Replies)
Discussion started by: brij123
5 Replies

6. Linux

how to automatically create a file?

how can i automatically create a file on Linux? like a process that searches for the file and if the file does not exist, it automatically makes the file (3 Replies)
Discussion started by: roozis
3 Replies

7. Shell Programming and Scripting

Getting the correct identifier in the output file

Hi All I do have a file like this: 1 1 12 26 289 3.2e-027 GCGTATGGCGGC 2 12 26 215 6.7e+006 TTCCACCTTTTG 3 9 26 175 8.9e+016 GCGGTAACT 4 20 26 232 1.7e+013 TTTTTATTTTTTTTTTTTCC 5 ... (6 Replies)
Discussion started by: Lucky Ali
6 Replies

8. Programming

How to get the correct exception file/line.

The below code throws error in the line number 32 where the function is defined. But How to find the line where the function is called. That is I want to throw the error at the line number 43 (as here the function is called). The code is: #include <iostream> #include <string>... (9 Replies)
Discussion started by: SamRoj
9 Replies

9. Shell Programming and Scripting

Open file with correct application

Can someone please help me with my bourne shell script. I am a struggling newbie. I need create a script that will read an argument from a command line, access a config file with application file types, and open the file with the correct application. The file needs to be able to handle file... (3 Replies)
Discussion started by: 3dtiger
3 Replies

10. UNIX for Advanced & Expert Users

Correct format in a log file

I'm trying to read the output of a .sql script (simple insert and commit oracle pl/slq script) to a log file using a shell script. My problem is I end up with a log file that looks like this: sd12@phenix97:/detain/sd12/logs > cat 20071205_detain_20071206.log 12320496 rows created. Commit... (11 Replies)
Discussion started by: sd12
11 Replies
Login or Register to Ask a Question