replacing charater


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replacing charater
# 1  
Old 05-23-2002
replacing charater

I need a help here. My administrator made some changes and we couldn't access some files any more.

I am trying to replace a list of files from one format to another. Can anyone help me please?

Here is an example of

aaa_bbbb_cccccc.03172002_02:30:08

How can I replace the ':' with '_' for all files of considering the fact there are different lenght of files, but with the same format.

Thanks,

Odogbolu98
Smilie
# 2  
Old 05-24-2002
Are those file names?
If so, you could do something like this:
Code:
for each in *:*; do mv $each `echo $each |tr : _`; done

This should work on reasonably modern shells.
If you have a specific shell in mind, it may be written a little differently, but this should work for general purposes. It may also fail if you have thousands of files in this directory...

If you have any problems, please post back.
# 3  
Old 05-24-2002
Thanks Livingfree for your help.

Due to the urgency of the problem. I had to settle for another solution.

What I did was,

ls| grep : | awk -F\: '{print $1 "_" $2 "_" $3}'

I was able to get the new name first and then copied the old file into the new name and erase the old file. This work fine. However I'll try my hand on your suggestion.

Thanks,

Odogbolu98
# 4  
Old 05-28-2002
Your method is probably safer - copy the file first, then remove later if everything worked correctly...

Either way works!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing tags

Hi , I have a file ...it's like a xml file. File 1: <tag1> Value11</tag1><tag2>value12</tag2> <tag1>Value21</tag1> ...... Continues Now what I want as output is Value11|value12 Value21|| ......Continues This is just learning purpose. I tried reading each line, then parsing... (14 Replies)
Discussion started by: Anupam_Halder
14 Replies

2. Shell Programming and Scripting

Replacing \n,\n with ,

Hi everyone, I've read lots of posts about tr and sed and such, I haven't been able to get out of this one. I have a file, like this: 1 , Jelle 2 , SandraThe only thing it needs to do is delete the enter between the number and the name. So, it needs to replace \n,\n with , ... (7 Replies)
Discussion started by: skerit
7 Replies

3. Shell Programming and Scripting

replacing / to -

Hi, i am running a shell script where i have assigned a variable to the value passed. so my variable is var1="investment/portfolio/run.job" now i want to assign another variable var2 as "investment-portfolio-run.out" how can i do it using awk or something else.... thanks (2 Replies)
Discussion started by: rudoraj
2 Replies

4. Shell Programming and Scripting

Replacing Characters

Hi All, I have a file which is delimeted with the character '. i need to replace this character with the same character and also a new line. Can anyone please help me with the tr command for this. Many thanks Karan (11 Replies)
Discussion started by: karansachdeva
11 Replies

5. Shell Programming and Scripting

Replacing of word

Hi all, I wanted to replace one word with another word pl help me to solve the same. example:- I wanted to replace RXOTX with RXOTRX in a perticuler file with hole. Regards, Ramesh (2 Replies)
Discussion started by: Ramesh Vellanki
2 Replies

6. Shell Programming and Scripting

replacing using sed

its again sed question. i have line - sed "s/$old/$new/g" "$f" > $TFILE && mv $TFILE "$f" working well if old="myoldfile" new="mynewfile" but if i want old="/home/shailesh/1test/" new="/home/shailesh/workspace/" it gives error like sed: -e expression #1, char 9: unknown option to... (2 Replies)
Discussion started by: shailesh_arya
2 Replies

7. Shell Programming and Scripting

Charater comparison

I have two files. Each file has one line with 2500 charaters in it and both lines should be the same, but thay are not. I need to compare the two lines and find where the differences are. So what I need to do is compare each character one at a time to find out whats different. (4 Replies)
Discussion started by: Tornado
4 Replies

8. Shell Programming and Scripting

help in replacing ??

hi all i have input file like this abc.txt filename.out: <TAB>ABC<TAB>9 <TAB>AKC<TAB>1 filename1.out: <TAB>XYZ<TAB>1 <TAB>XYN<TAB>4 and i am trying to replace \n\t with \t so that output will be like this: filename.out:<TAB>ABC<TAB>9<TAB>AKC<TAB>1... (5 Replies)
Discussion started by: zedex
5 Replies

9. UNIX for Dummies Questions & Answers

Inserting a delimiter after certain charater position

Hi, I have a string : - ICFFHASMTAAMPFINCL22082006000002548789632 and i want to add delimiter after certain charater position through a script, eg. ICFFH,ASMTAAMPF,INCL,22082006,000002548789632. I have tried and am able to achieve it through cut-paste. But i don't want to use cut paste as it... (6 Replies)
Discussion started by: divz
6 Replies

10. Shell Programming and Scripting

running an Acii charater in a script.

Hi, I need to pass a space bar or an enter key in a script for it to return control to my script. How do I do this. For example the spacebar ascii value is 127, how do I tell the script to run this command. (4 Replies)
Discussion started by: quispiam
4 Replies
Login or Register to Ask a Question