Shell Script Help..Renaming Quoted files removing the timestamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script Help..Renaming Quoted files removing the timestamp
# 8  
Old 11-05-2015
Hi Don,

Thanks for ur reply.
POSIX I am not sure of.. Smilie
But yes - the script is a .csh script.
Shell gives me a $ prompt.
I am working on the script through putty utility.
Also,if you could explain the
Code below, it will help me to understand better how to incorporate it in my script.
Code:
 FN="'ABDDUT20513'13May06:03:45"
echo mv "$FN" "${FN%\'*}'"


Thanks & Regards,
Khman.
# 9  
Old 11-05-2015
The code we supplied assumed that you were using a shell that uses the same syntax as the shell in the POSIX standards (such as ash, bash, dash, ksh, zsh, and many others). But, csh and shells that use its syntax (such as tcsh) are a completely different language when it comes to parameter expansions.

If you want to use csh, other volunteers here may be able to help you.
# 10  
Old 11-05-2015
Quote:
Originally Posted by looney
Hi Don,

Kindly brief about % in code echo mv "$FN" "${FN%\'*}'"
Thanks,
From the standards (or your shell's man page):
Code:
${parameter%word} Remove Smallest Suffix Pattern.
	The word shall be expanded to produce a pattern. The parameter
	expansion shall then result in parameter,  with the smallest portion
	of the suffix matched by the pattern deleted.  If present, word shall
	not begin with an unquoted '%'.

This is not supported by csh and other shells that use csh syntax.

So, for this thread, with filenames that start with a single quote and contain one other single quote, this parameter expansion expands to the contents of the variable with everything starting with the second single quote to the end of the filename replaced by a single single quote.
# 11  
Old 11-05-2015
In csh, command substitution should work (albeit ineffectively):
Code:
FN="'filename20513'13May06:03:45"
echo mv "$FN" `echo "$FN" | sed "s/[^\']*$//"`
mv 'filename20513'13May06:03:45 'filename20513'

These 2 Users Gave Thanks to RudiC For This Post:
# 12  
Old 11-06-2015
Hi Don,

Thanks for the update.

Hi RudiC,

Thank you for your response.
Can you plz explain me the code?
It will help me to understand and then incorporate in my script.

Also, one of the colleagues gave me a suggestion to use
Code:
awk command

... and then a field separator.

Can you guys help me on that..?

Thanks as always for your valuable time and help on this.

Thanks & Regards,
khman.
# 13  
Old 11-06-2015
man csh:
Quote:
Command Substitution A command enclosed by backquotes (`...`) is performed by a subshell. Its standard output is broken into separate words at each space character, tab and newline; null words are discarded. This text replaces the backquoted string on the current command line. Within double-quotes, only newline characters force new words; space and tab characters are pre- served. However, a final newline is ignored. It is therefore possible for a command sub- stitution to yield a partial word.
So the result of the sed substitution will be used as the target for the mv command.

I don't see awk being able to provide a significant improvement to above proposal.
This User Gave Thanks to RudiC For This Post:
# 14  
Old 11-06-2015
Thanks RudiC for your help.
But my filename is dynamic.

So when i used the above code to assign the file name to a variable, lets say FN or TEMPFILE... it gives the below error

Code:
set TEMPFILE=`\'*\'${date}*`
'ABCCDT20513'13May06:03:45
'ABCCDT20513'13May06:03:45: Command not found.

In above case value for
Code:
$date variable

passed is 13May

How should I assign the dynamically created file name to a variable so that i can do further processing on that variable containing the quoted file name in the
Code:
 mv command

?

Thanks & Regards,
Khman.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find and removing the old files and zipping the files using shell script

Hi, I am trying to removing the old files which were older than 10 days and same g zipping the files using the shell script. script was return as follows. find /jboss7_homes/JBOSS7/SKYLIV??/SKYLIV??_CRM/jboss-eap-7.0/standalone/log -mtime +10 -type f | xargs rm -f find /cer_skyliv??/log... (6 Replies)
Discussion started by: venkat918
6 Replies

2. Shell Programming and Scripting

Shell Script for renaming and moving Files - Easy?

Hey guys, ive been working on this for about 2hrs now - without any solution. At first I need to say I dont have skills in linux bash scripting, but I tried to use some codesnippets and manuals from google. What I want to do: I have different folders including 2 different filestypes with... (15 Replies)
Discussion started by: peter1337
15 Replies

3. UNIX for Dummies Questions & Answers

Renaming Multiple Files by removing characters

Hi I would like to rename Multiple files in a Unix Directory using Ksh Command. Eg ATT8-2011-10-01 00:00:00-MSA-IMM-SINGLE_AND_FAMILY_COVERAGE-DED-$2000-X114817.PDF needs to be renamed as ATT8-2011-10-01-MSA-IMM-SINGLE_AND_FAMILY_COVERAGE-DED-$2000-X114817.PDF Basically the time... (2 Replies)
Discussion started by: pchegoor
2 Replies

4. Shell Programming and Scripting

Need help in batch renaming files with bash shell script.

I have some 50+ files in the following format : abcd_vish_running_ZEBRA_20140818.dat_08-14-2014_23:08:23 abcd_vish_running_ZEB-RA_20140818.dat_08-14-2014_23:08:35 abcd_vish_running_ZEB_RA_20140818.dat_08-14-2014_23:08:37 abcd_vish_running_RI-NG_20140818.dat_08-14-2014_23:08:42... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

5. Shell Programming and Scripting

Renaming multiple files with a shell script

Hey guys, I'm really new to UNIX and shell scripting in general. For my internship I need to rename a bunch of files. Specifically, I need to change the first letter of each of the files to lowercase and I have to change the endings so they all basically look like "file_cone.jpg". I know I... (4 Replies)
Discussion started by: jjzieve
4 Replies

6. UNIX for Dummies Questions & Answers

Shell script which will sort all the files in a directory with the timestamp they were created

Team, Pls help writing a shell script which will sort all the files in a directory with the timestamp they were created. (like ls -lrt) (6 Replies)
Discussion started by: asappidi
6 Replies

7. Shell Programming and Scripting

Need help with shell script for moving/deleting/renaming files

Hi. I need help with a little script that will be used to move some files to their parent directory, delete the directory, rename one file in the parent directory and delete another, then continue to the next. Here's an example: /var/media/Music/Genesis/1970 album - Trespass (2008 Box -... (4 Replies)
Discussion started by: aflower
4 Replies

8. UNIX for Dummies Questions & Answers

Removing prefix from multiple files and renaming file extension

Hello i have the files in this format pdb1i0t.ent pdb1lv7.ent pdb1pp6.ent pdb1tj2.ent pdb1xg2.ent pdb2b4b.ent pdb2ewe.ent Now i have to remove the prefix pdb from all the files and also i need to change the extension of .ent to .txt The new file should look like this ... (3 Replies)
Discussion started by: empyrean
3 Replies

9. UNIX for Dummies Questions & Answers

Renaming Files using Shell Script

Hi Gurus, I have some files(all ending with .out as extension). Ex: aa1.out aa2.out aa3.out I would like to append each file with the current date to the end of the file so that they should become aa1_20090504.out. So I am using rename as follows: for i in path/aa* ; do mv $i... (5 Replies)
Discussion started by: asmfloyd
5 Replies

10. Shell Programming and Scripting

copying files and Renaming them + shell script

Hi, I have a problem. I have some text files in a folder. The names can be like: emp.txt emp1.txt emp3.txt 32emp4.txt What i need is i have to copy all the files which have "emp" string in their filename to a different folder and those file names... (7 Replies)
Discussion started by: pathanjalireddy
7 Replies
Login or Register to Ask a Question