Edit last parameter in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Edit last parameter in a file
# 1  
Old 07-13-2010
Edit last parameter in a file

I have a script in which I am trying to move some files.

Code:
find DIR1|awk -F/ '{print "mv " $0, $0}'|sed -e "s/${DIR1}/&.OLD/g" -e 's/.OLD//'

which gives me:

Code:
mv DIR1/abc DIR1.OLD/abc
mv DIR1/abc/tmp DIR1.OLD/abc/tmp

What I would like to do is change the command to print:

Code:
mv DIR1/abc DIR1.OLD/.
mv DIR1/abc/tmp DIR1.OLD/abc/.

Does anyone have an idea how to do this?

Thanks

---------- Post updated 13-07-10 at 09:19 ---------- Previous update was 12-07-10 at 13:21 ----------

I've worked out a way to do this - not as elegant as I would like, but it seems to work:

Code:
for i in `find DIR1`; do
do
  LAST=`echo $i|awk -F/ '{print $NF}'`
  echo $i|sed -e "s!${DIR1}!&@!" -e 's!^.*!mv & &!' -e 's!@!!' -e 's!@!.OLD!' -e "s/${LAST}$/./"
done



---------- Post updated at 09:23 ---------- Previous update was at 09:19 ----------

It should be:

Code:
echo $i|sed -e "s!${DIR1}!&@!" -e 's!^.*!mv & &!' -e 's!@!!' -e 's!@!.OLD
!' -e "s/${LAST}$/\/./"


Last edited by radoulov; 07-13-2010 at 06:35 AM.. Reason: code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get the parameter value from the parameter file in perl?

hi all, i have a parameter file of following format, i want a method which can get the value of specific parameter. parameter file format: <Parameter Name="FileLocationWindows"> <Description> The directory location of the logger file. ... (1 Reply)
Discussion started by: laxmikant.hcl
1 Replies

2. UNIX for Advanced & Expert Users

Edit file

Hi All, I have file with 200K Records and each line with 400 character. I need to edit the some part of the file. For example, i need to edit character from 115 to 125, 135to 145 and 344 to 361 Can you please anyone help me to do this? Regards, (1 Reply)
Discussion started by: balasubramani04
1 Replies

3. Shell Programming and Scripting

Command that takes one parameter and then searches for the passed in parameter

Hi I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/ Can anyone please help me on this? (3 Replies)
Discussion started by: pankaj80
3 Replies

4. Shell Programming and Scripting

Best way to edit a file

looking for a script or command to push out from a centralized machine to multiple machines. I have the software in place that will do this already, but I need to tell it what command to run on each machine with this file. what I need is a script or command to edit a file in a specific manner.... (13 Replies)
Discussion started by: skunky
13 Replies

5. Shell Programming and Scripting

edit file

I have a file containing dates like below 2010 1 02 2010 2 01 2010 3 05 i want the dates to be like below 20100102 20100201 20100305 i tired using awk '{printf "%s%02s%02s",$1,$2,$3}' But it does not work,it puts all the dates in one line,i want them in seperate lines like the... (6 Replies)
Discussion started by: tomjones
6 Replies

6. Shell Programming and Scripting

Script to Edit the file content and create new file

I have a requirement, which is as follows *. Folder contains list of xmls. Script has to create new xml files by copying the existing one and renaming it by appending "_pre.xml" at the end. *. Each file has multiple <Name>fileName</Name> entry. The script has to find the first occurance of... (1 Reply)
Discussion started by: sudesh.ach
1 Replies

7. Linux

Parameter to edit in /etc/fstab in RH 8.0

Hi All, In RH 8.0, I am not able to mount USB pendrive. I know one method where in /etc/fstab is to be edited, so that it points to a directory /mnt/usb. After that it mount automatically. Unfortunately, i have forgotten the parameter to add in /etc/fstab-can anyone help me please? Thanks... (1 Reply)
Discussion started by: scriptlearner
1 Replies

8. UNIX for Dummies Questions & Answers

edit a .fs file

I have a .fs file that I want to edit, (or just be able to see what is in it) preferably through a windows environment. Does anyone know how to do that? Thanks (4 Replies)
Discussion started by: kiterboy
4 Replies

9. Shell Programming and Scripting

how do I make dynamic parameter names? Or get the value of a parameter evaluated twi

Say I write something like the following: var1=1 var2=2 for int in 1 2 do echo "\$var$int" done I want the output to be: 1 2 Instead I get something like: $var1 $var2 (2 Replies)
Discussion started by: Awanka
2 Replies

10. Shell Programming and Scripting

file edit help

Hi, Could anyone give me a idea how to strip the lines from a given file. example *********** 1st occurence 1st occurence 1st occurence 1st occurence *********** 2nd occurence 2nd occurence 2nd occurence 2nd occurence 2nd occurence 2nd occurence ************* 3rd occurence 3rd... (10 Replies)
Discussion started by: sentak
10 Replies
Login or Register to Ask a Question