Replace path in a file with dot


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace path in a file with dot
# 1  
Old 04-23-2007
Replace path in a file with dot

Hi,
I have a file with below values.

/uvxapps/etl/Ascential/DataStage/DSEngine/dsenv.orig
/uvxapps/etl/Ascential/DataStage/DSEngine/dsenv
/uvxapps/etl/Ascential/DataStage/DSEngine/sample/.cshrc
/uvxapps/etl/Ascential/DataStage/DSEngine/sample/.login
/uvxapps/etl/Ascential/DataStage/Config/sample/f1.txt
/uvxapps/etl/Ascential/DataStage/Config/sample/f2.txt


I need to replace the path (not full path) with . (dot)

Below will be the information that I will be having.
$GroupDir will be from a the part of the path that needs to be replaced with . (dot). If GroupDir=/uvxapps/etl/Ascential then I want the output to look like

./DataStage/DSEngine/dsenv.orig
./DataStage/DSEngine/dsenv
./DataStage/DSEngine/sample/.cshrc
./DataStage/DSEngine/sample/.login
./DataStage/Config/sample/f1.txt
./DataStage/Config/sample/f2.txt

cat ${BackupDir}/ArchCom.tmp | sed "s;${GroupDir};\.;" > ${BackupDir}/ArchCom.txt

I tried the above in my shell script but did not work. Where as the same command works fine when executed @ command line. (I set the values of GroupDir & BackupDir in the command line where as it is through parameter in the shell script)

Thanks.

Last edited by njoshi; 04-23-2007 at 09:40 PM.. Reason: Delete
# 2  
Old 04-23-2007
I had no problem with the following

Code:
#!/bin/sh

GroupDir=/uvxapps/etl/Ascential
cat ArchCom.tmp | sed "s;${GroupDir};\.;"

# 3  
Old 04-23-2007
Sorry guys, the problem being faced is due to another issue. My apologies for the inconvenience.
# 4  
Old 04-23-2007
Code:
a="/uvxapps/etl/Ascential"
awk  -v var="$a" '{gsub(var, "",$1 );print $1}' "file"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How i can add via preg replace dot after numbers ?

So lets say i have file my_birthday.402.zip ho it can became my_birthday.4.0.2.zip Thank you :) (1 Reply)
Discussion started by: ZerO13
1 Replies

2. Shell Programming and Scripting

Replace null values with dot using awk

Using awk I am trying to replace all blank or null values with a . in the tad delimited input. I hope the awk is close. Thank you :). input name test sam 1 liz 2 al 1 awk awk 'BEGIN{FS=OFS="\t"}{for(i=1;++i<NF;)$i=$i?$i:"."}1'input awk 'BEGIN { FS =... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

sed - search and replace whole string which contains dot

Hello. I would like to search exactly "string1.string2.string3" and replace it by "new_string1.new_string2.new_string3" And I would like to search exactly "string2.string3" and replace it by "new_string2.new_string3" And I would not found in the result : "string1.new_string2.new_string3"... (3 Replies)
Discussion started by: jcdole
3 Replies

4. Shell Programming and Scripting

Replace dot with semicolon in PERL

Hi, I have a file in PERL in the following pattern filename| 06-Dec-11 03.04.14.000000 PM filename1| 06-Dec-11 05.05.14.000000 PM I need to replace .(dot) with :(semicolon) in the timestamp value of the file How can this be done. Any help will be appreciated Thanks in advance (5 Replies)
Discussion started by: irudayaraj
5 Replies

5. Shell Programming and Scripting

How to replace quote symbol(") and dot(.) with some other values!!

Hi , I have below input file 1.order number is useful. 2.vendor_id is produced. 3.the vandor name is "malawar". I want output file like 1. order number is useful. 2. vendor_id is produced. 3. the vandor name is VmalawarV. in input file line number 1.order number there is no... (4 Replies)
Discussion started by: vinothsekark
4 Replies

6. Shell Programming and Scripting

How to search/replace a directory path in a file using perl

Hello All, Here is what I am trying to do and maybe you guys can point me in the right direction. I have a file that contains the following string(s): WARNING: </d1/test/program1> did not find item1 WARNING: </d1/test/program1> item1 does not exist WARNING: </d1/test/program2> item1 failed... (1 Reply)
Discussion started by: maxshop
1 Replies

7. Shell Programming and Scripting

Dot in front of cmd path

Hi, I have come across this cmd in a sh script (Bourne): . /orabin/appbin/myfilename.env There is a . (dot) in front of the file path. Would like to know what is the meaning of the dot. Thanks. (3 Replies)
Discussion started by: joe_x
3 Replies

8. Shell Programming and Scripting

Find and replace string from file which contains variable and path - SH

e.g. /home/$USER/.config replace it with "" (empty) Is this possible? I think you should play a bit with sharps ## and sed:b: (2 Replies)
Discussion started by: hakermania
2 Replies

9. Shell Programming and Scripting

serach and replace file name in the path in a remote xml file

hi every one , here is my problem !! i have to run my script from an account and update the result in a xml file located on a different account. i use existing ssh keys to do it remotely for example the tags looks like this <PropertyValueList... (1 Reply)
Discussion started by: kiranreddy1215
1 Replies

10. Shell Programming and Scripting

Replace a Directory path with another in a file

Hi, I have abt 20-30 scripts using a directory structure. I have to replace a directory structure in a file for example "/i01/proc" with "/dwftp/scripts" using sed. The command :- cat filename | sed 's/"i01/proc"/"dwftp/scripts"' is not working. Can someone help me in this regard? ... (3 Replies)
Discussion started by: venkatajay_18
3 Replies
Login or Register to Ask a Question