Rename file using sed command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename file using sed command
# 15  
Old 04-28-2010
Quote:
Originally Posted by fanny_tirtasari
Hi Franklin,

Not sure what is wrong with my unix box, but the result for the latest code come up with below error :

awk: syntax error near line 1
awk: bailing out near line 1
Use nawk or /usr/xpg4/bin/awk on Solaris.
# 16  
Old 04-28-2010
Quote:
Originally Posted by Franklin52
Use nawk or /usr/xpg4/bin/awk on Solaris.
Hi Franklin,

Still no luck Smilie.

I used /usr/xpg4/bin/awk and the result is like following :
/usr/xpg4/bin/awk: syntax error Context is:
>>> 20100428193054 {of=sprintf("%02d.xml",++c) print <<<

And when using nawk the result is like following :
nawk: syntax error at source line 1
context is
{of=sprintf("%02d.xml",++c) >>> print <<< "mv " $0 " " dat of}
nawk: illegal statement at source line 1

---------- Post updated at 07:35 PM ---------- Previous update was at 07:33 PM ----------

Quote:
Originally Posted by jim mcnamara
You may be using a shell the other posters are not expecting. Be sure there are no spaces between = and $( as in dat=$(

Do you know if you have bash, bourne, ksh, zsh....? which one?
Hi Jim,

There are no spaces between = and 4( in dat=$(.
Im sure of that.

but not sure for bahs, bourne or zsh.
But the other program in my unix box are having ext ksh or sh or prog.
# 17  
Old 04-28-2010
what about Scrutinizer's solution?
Did you try that?
# 18  
Old 04-28-2010
Quote:
Originally Posted by anchal_khare
what about Scrutinizer's solution?
Did you try that?
Hi Anchal and scrutinizer,

i did try the solution but come up with below error :
" syntax error at line 6: `i=$' unexpected" in my unix box
# 19  
Old 04-28-2010
Quote:
Hi ygemici,

i got below error if i run your code in my unix box :

renamef4.sh: filestmp: Permission denied

Files
--------------
cat: cannot open filestmp
renamef4.sh: filestmp: No such file or directory

New Files
--------------
Is there write permission yourself in dir?
please the output in your dir that script works
Code:
ls -ld

# 20  
Old 04-28-2010
Are you still facing issue with the solution which I have provided ?
# 21  
Old 04-28-2010
Quote:
Originally Posted by pravin27
Are you still facing issue with the solution which I have provided ?
Hi Pravin,

Nope, your solution working well with minor adjustment... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed replace to rename each line a file

Have a file in this format This is line one ; line_one This is line two ; line_two This is line three ; line_three This is line four ; line four. I'm trying to make each line a new file called line_one line_two line_three line_four. Tried using split -1 but then I'm back needing to rename... (3 Replies)
Discussion started by: jimmyf
3 Replies

2. Shell Programming and Scripting

Command / script to partially rename file

Hi I have numerous files names product_host_result_B1000842.txt product_host_result_B1000847.txt product_host_result_C1000842.txt product_host_result_C1000848.txt etc. I need them renamed so that the 'product_host_result' becomes 'output_product_host' but the rest of the filename is... (6 Replies)
Discussion started by: Grueben
6 Replies

3. UNIX for Dummies Questions & Answers

Rename scripts using xargs/sed

Morning all I've got loads of scripts but the names are too long! I've stuck the list in a flat file (names) and I'm trying to read that in line by line and create the new names (in to directory new) from the list. It looks like this: xargs -n1 -I{} <names cat {} | sed... (1 Reply)
Discussion started by: Grueben
1 Replies

4. Shell Programming and Scripting

sed file rename

Ubuntu -very new to shell scripts/Linux I have many pictures with "FAMILY", "family" mixed in the file name and not all in the same directory; I want to remove "family" case insensitive from the filenames; find /media/Rock/pics/pics_bak/ -type f "*family*" | sed 's#family##gI' # works for... (2 Replies)
Discussion started by: jennyjones
2 Replies

5. Shell Programming and Scripting

Rename file using sed or awk

I have a filename like 1_DATE_3_4.5_888 and I want to modify the date field (ie the last 4 digits ) alone and remove the last field. Old filename:1_DATE_3_4.5_888 Given date (for eg):120606259532 modified date:120606259899 new filename:1_<modified date>_3.4.5 (14 Replies)
Discussion started by: sandy88
14 Replies

6. Shell Programming and Scripting

try to batch rename using sed (if this is best)

hi gooday I need some help with a rename I am attempting. I'd like to rename a bunch of files in a folder example list.dat.old to list_N.dat query.dat.old to query_N.dat note the two periods in (.dat.old) to become _N.dat I tried using sed like this ls *.dat.old | sed... (3 Replies)
Discussion started by: johnstrong
3 Replies

7. Shell Programming and Scripting

Multiple file rename (change in filename in unix with single command

Dear All, Please help ! i ham having 300 file with E.G. PMC1_4567.arc in seq. like PMC1_4568.arc,PMC1_4569.arc ...n and so on.. i want all those file to be rename like PMC_4567.arc ,PMC_4568.arc .. mean i want to remove 1 from first file name .. pls help.. (6 Replies)
Discussion started by: moon_22
6 Replies

8. UNIX for Advanced & Expert Users

Unix Command to rename a file in a zipped folder

Hi, I am into automation work. Is there any UNIX command to rename a file in a zipped folder, without unzipping it..??? Thanks in advance.. (1 Reply)
Discussion started by: Victoria.Sam
1 Replies

9. Shell Programming and Scripting

mv command to rename multiple files that retain some portion of the original file nam

Well the title is not too good, so I will explain. I need to move (rename) files using a simple AIX script. ???file1.txt ???file2.txt ???file1a.txt ???file2a.txt to be: ???renamedfile1'date'.txt ???renamedfile2'date'.txt ???renamedfile1a'date'.txt ???renamedfile2a'date'.txt ... (4 Replies)
Discussion started by: grimace15
4 Replies

10. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies
Login or Register to Ask a Question