sed -Replacing file path within .txt file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed -Replacing file path within .txt file
# 1  
Old 05-07-2012
sed -Replacing file path within .txt file

Hi,

I am trying to use sed to replace a file path within all the .lay (.txt) files in a folder. I feel that this should be easy but I can't get it to work no matter what i try.

I'm using cygwin.

For a .txt file containing the below line I want to replace this file path with a new one.
Code:
$!VarSet |LFDSFN1| = '"E:\OLD\FILE\PATH TO DATA\data.txt"

Below is what i think should work.
Code:
old_file_path="E:\OLD\FILE\PATH TO DATA\data.txt"
new_file_path="E:\new\file\path"

sed -e 's|$old_file_path|$new_file_path|g' *.lay

I've tried placing the variables inside the command, defining the input and output files. I've changed the delimeter to |, as using back or forward slashes is problematic with file names. I have tried other methods on fouums, but can't get anything to work.

Last edited by jim mcnamara; 05-07-2012 at 10:28 PM.. Reason: code tags
# 2  
Old 05-07-2012
Code:
find . -type f -name "*lay"  -exec grep -q "$old" {} \; -exec sed -i "s|$old|$new|g" {} \;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux Commands needed for replacing variable number of spaces with a single , in a txt file

Hi I want to read a text file and replace various number of spaces between each string in to a single "," or any other character .Please let me know the command to do so. My input file is a txt file which is the output of a SQL table extract so it contains so many spaces between each column of the... (2 Replies)
Discussion started by: Hari Prasanth
2 Replies

2. Shell Programming and Scripting

Replacing a line in a file using sed

I have a file which has a list in it pop triangle people slow fast What I want to do is search this list and replace people with humans do the list looks like this: pop triangle human slow fast I think i use something like this.... if cat /list.txt | grep -q 'people' ; then (9 Replies)
Discussion started by: digitalviking
9 Replies

3. Shell Programming and Scripting

sed command for copying the contents of other file replacing it another file on specifc pattern

We have 2 file XML files - FILE1.XML and FILE2.xml - we need copy the contents of FILE1.XML and replace in FILE2.xml pattern "<assignedAttributeList></assignedAttributeList>" FILE1.XML 1. <itemList> 2. <item type="Manufactured"> 3. <resourceCode>431048</resourceCode> 4. ... (0 Replies)
Discussion started by: balrajg
0 Replies

4. Shell Programming and Scripting

SED and replacing Txt Bullet

Hi Guys, I'm sure that there is simple solution .. I googled .. it and nothing is coming up ... ( I Tried it as hex 0xE2 no luck ) sed -e 's/•/X/g' data.txt > data1.txt I'm trying to replace bullet with X Actually VI editor shows this sign: ¥ But it doesn't work - I'm sure that SED... (7 Replies)
Discussion started by: NDxiak
7 Replies

5. UNIX for Dummies Questions & Answers

Problem writing file path to txt file

if test -z "$1" then echo "you must give a filename or filepath" else path=`dirname $1` f_name =`basename $1` if path="." then path=`pwd` fi fi cat $f_name $path >> index.txt The only problem I am encountering with this is writing $path to index.txt Keeps going gaga: cat:... (1 Reply)
Discussion started by: Vintage_hegoog
1 Replies

6. Shell Programming and Scripting

sed to remove last 2 characters of txt file

sed 's/^..//' file1.txt > file2.txt this will remove the first two characters of each line of a text file, what sed command will remove the last two characters? This is a similar post to my other....sry if I'm being lazy.... I need a file like this (same as last post) >cat file1.txt 10081551... (1 Reply)
Discussion started by: ajp7701
1 Replies

7. Shell Programming and Scripting

Input file redirect in output path and want name as inputfilename_new.txt

not required this time (6 Replies)
Discussion started by: Sandeep_Malik
6 Replies

8. UNIX for Dummies Questions & Answers

Binary txt file received when i use uuencode to send txt file as attachment

Hi, I have already read a lot of posts on sending attachments in unix...but none of them were of help for my problem...so here goes.. i wanna attach a text file and send to a mail id..used the following code : uuencode "$File1" "$File1" ;|mail -s "$Mail_sub" abc@abc.com it works... (2 Replies)
Discussion started by: ash22
2 Replies

9. Shell Programming and Scripting

sed script to print a value from txt file

Hello guys, I would appreciate if someone can help me to write a shell script using sed. From a larget text file I need to print a fixed value of a word. In another words whenever it finds that word, it needs to grab the other line containing "dn" and prints its value. For example: dn:... (7 Replies)
Discussion started by: cmontr
7 Replies

10. UNIX for Dummies Questions & Answers

vi - replacing a relative path with absolute path in a file

Hi, I have a file with about 60 lines of path: app-defaults/boxXYZ....... I want to change this to /my/path/goes/here/app-defaults/boxXYZ, but of course vi doesn't like the regualr :s/old/new/ command. Is there any other quick way to do this? Thanks ;) (2 Replies)
Discussion started by: Yinzer955i
2 Replies
Login or Register to Ask a Question