Rename in C Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename in C Shell
# 1  
Old 11-01-2010
Error Rename in C Shell

i want to rename this files.

#ANTB.BHZ.KO
#ANTB.BHE.KO
#ANTB.BHN.KO

they have to be like this
#2010-10031749_ANTB.BHZ
#2010-10031749_ANTB.BHE
#2010-10031749_ANTB.BHN


plz help meSmilie





#ANTB.BHZ.KO
#2010-10031749_ANTB.BHZ
# 2  
Old 11-01-2010
Renaming is use of the mv command, not really a shell thing one way or the other. I suppose we are talking about list processing, something that might as well be done in sed and sent to any shell:
Code:
 
ls '#'*.KO | sed '
  p
  s/#\(.*).KO$/#'`date "+%Y-%m%m%H%M"`'_\1/
 ' | sed '
  N
  s/\n/ /
  s/^/mv /
' | csh

Narrative: list any #*.KO files into sed, which sends each on unmodified as source and then rewrites the file name to the desired format with the current timestamp. (hopefully clock time is OK, or did you want the file mod time?) The second sed get the pair of lines and reformats them to "mv source target" and sends the dynamically generated script to a shell.
This User Gave Thanks to DGPickett For This Post:
# 3  
Old 11-02-2010
Error

Quote:
Originally Posted by DGPickett
Renaming is use of the mv command, not really a shell thing one way or the other. I suppose we are talking about list processing, something that might as well be done in sed and sent to any shell:
Code:
 
ls '#'*.KO | sed '
  p
  s/#\(.*).KO$/#'`date "+%Y-%m%m%H%M"`'_\1/
 ' | sed '
  N
  s/\n/ /
  s/^/mv /
' | csh

Narrative: list any #*.KO files into sed, which sends each on unmodified as source and then rewrites the file name to the desired format with the current timestamp. (hopefully clock time is OK, or did you want the file mod time?) The second sed get the pair of lines and reformats them to "mv source target" and sends the dynamically generated script to a shell.

programme said :

Unmatched '.

Last edited by yemenja; 11-02-2010 at 05:47 AM..
# 4  
Old 11-02-2010
guess there is a missing backslash in the first sed command..
Code:
s/#\(.*\).KO$/#'`date "+%Y-%m%m%H%M"`'_\1/

This User Gave Thanks to michaelrozar17 For This Post:
# 5  
Old 11-02-2010
Error

Quote:
Originally Posted by michaelrozar17
guess there is a missing backslash in the first sed command..
Code:
s/#\(.*\).KO$/#'`date "+%Y-%m%m%H%M"`'_\1/


but i think there is another mistake because when i make csh rename.csh it says again

Unmatched '.

i havent found why it happened Smilie
# 6  
Old 11-02-2010
Yes,
and '%m%m' s/b '%m%d',
and in csh, you have to escape linefeed inside single quotes.
Well, it helps to have one to test with. Smilie
Short doses of csh are enough!

You can call ksh scripts even in csh, as long as they are executable and begin with #!/usr/bin/ksh (or wherever your ksh is)!

Last edited by DGPickett; 11-02-2010 at 06:02 PM..
# 7  
Old 11-09-2010
CPU & Memory

Quote:
Originally Posted by DGPickett
Yes,
and '%m%m' s/b '%m%d',
and in csh, you have to escape linefeed inside single quotes.
Well, it helps to have one to test with. Smilie
Short doses of csh are enough!

You can call ksh scripts even in csh, as long as they are executable and begin with #!/usr/bin/ksh (or wherever your ksh is)!

but i have to write in Cshell Smilie can anybody else help?SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help required with a file rename shell script

Hello everyone, Posting here after a long time, been away from unix world lately and it seems I have forgotten my shell scripting completely. I have a requirement where a csv file contains following columns: Full Registration VIN Stock... (14 Replies)
Discussion started by: tayyabq8
14 Replies

2. Shell Programming and Scripting

Shell script to get one to one map and rename the filename

I have 2 files sorted by numerically. I need help with shell script to read these 2 files and do a 1:1 mapping and rename the filenames with the mapped case#; For example: cat case.txt 10_80 10_90 cat files.txt A BCD_x 1.pdf A BCD_x 2.pdf ls pdf_dir A BCD_x 1.pdf A BCD_x 2.pdf ... (2 Replies)
Discussion started by: iaav
2 Replies

3. Shell Programming and Scripting

write shell script to rename file

hi, I need some help in writing shell script in a bourne shell.I am trying to rename the file.. eg. find /root/data -type f -name "text*) | while read FILES do newfile=${FILES/type_2.0_20101208_34.xml / tmp.xml} mv "$FILES" "$newfile" done above written script is working...If the... (7 Replies)
Discussion started by: shubhig15
7 Replies

4. Shell Programming and Scripting

Shell script to rename a group of files

Hello, I am having 1800 files in a directory with a specified format, like amms_850o_prod.000003uNy amms_850o_prod.000003u8x amms_850o_prod.000003taP amms_850o_prod.000003tKy amms_850o_prod.000003si4 amms_850o_prod.000003sTP amms_850o_prod.000003sBg amms_850o_prod.000003rvx... (12 Replies)
Discussion started by: atlantis
12 Replies

5. Shell Programming and Scripting

Need help for a Shell script to rename multiple files

Hi! I need help to create a shell script to search inside a file and then copy a portion of the search result as the new file name. Basically I was hacked over the weekend and the genius wipe out my drive from my server. I was able to recover alot of files, but biggest problem Is now the... (15 Replies)
Discussion started by: kidney514
15 Replies

6. Shell Programming and Scripting

Shell Script to rename files

Hi, i need a bit of help writting a tcsh script which renames all ascii text files in the current directory by adding a number to their names before the extension so for example, a directory containing the files Hello.txt Hello.t Hello should have the following changes, Hello.txt... (2 Replies)
Discussion started by: yakuzaa
2 Replies

7. Shell Programming and Scripting

Shell script to rename files with .1,.2,.3 ....ext respectively

Hey Guys.... Just need some help as I am not proficient in Unix shell script... Doubt: --------------- Suppose there will be some of the following files inside a directory called OUT ... Path: - /appdb1/product/batch/rms/OUT files inside OUT directory:- POSU_75002_20090127_20090129035442... (4 Replies)
Discussion started by: satyajit007
4 Replies

8. Shell Programming and Scripting

copy/rename file as date() unix/shell

File.jpg I want to copy and rename this as 2008-12-02.jpg I tried this copy File.jpg date '%y-%m-%d-%H:%M:%S'.jpg This doesnt work.... what do i do? (1 Reply)
Discussion started by: hdogg
1 Replies

9. Shell Programming and Scripting

How to Rename/Convert Files in Shell Scripting?

Hi All, I want to Rename/Convert all the .doc files in to .pdf format. I am using the following Script. But the final output is not proper. ########################################## cd /u13/prepaid/ftpdata/INfiles/sap/ for name in `ls *.doc` do name1=`echo $name | sed -e... (11 Replies)
Discussion started by: hanu_oracle
11 Replies

10. Shell Programming and Scripting

rename files using shell scripting

Hi all, i want to rename some files in my directory using korn shell scripting. 1) i want to rename files who have no extension so that they will have the format: filename.extension and 2) i want the files who has extension initially, to stay the same (they will not be... (4 Replies)
Discussion started by: gfhgfnhhn
4 Replies
Login or Register to Ask a Question