Replacing text within a line 
Author Message
 Replacing text within a line

Hi,

if anyonje out there can help it would be gratefully appreciated.

I have a file of text. Within that file I want to find a particular line and
edit it i.e.

the line:

Library_Path=$MDR/ext/gfd/hort:$Library_Path:/ext/df1; export Library_path

and I want the output to be

Library_Path=$Library_Path:/ext/df1; export Library_Path.

That is I want to remove the "$MDR/ext/gfd/hort" from the line.

I have tried substituting but to no avail.

Thanks for any help in advance.



Tue, 13 Nov 2001 03:00:00 GMT  
 Replacing text within a line
Have you tried something like:

awk ' { SF="$MDR/ext/gfd/hort:" } { print $1$2 }'

Quote:

> Hi,

> if anyonje out there can help it would be gratefully appreciated.

> I have a file of text. Within that file I want to find a particular line and
> edit it i.e.

> the line:

> Library_Path=$MDR/ext/gfd/hort:$Library_Path:/ext/df1; export Library_path

> and I want the output to be

> Library_Path=$Library_Path:/ext/df1; export Library_Path.

> That is I want to remove the "$MDR/ext/gfd/hort" from the line.

> I have tried substituting but to no avail.

> Thanks for any help in advance.



Tue, 13 Nov 2001 03:00:00 GMT  
 Replacing text within a line


Quote:
>Have you tried something like:

>awk ' { SF="$MDR/ext/gfd/hort:" } { print $1$2 }'

You probably transposed the "S" and "F", and meant FS and not SF

Chuck Demas
Needham, Mass.

Quote:


>> Hi,

>> if anyonje out there can help it would be gratefully appreciated.

>> I have a file of text. Within that file I want to find a particular line and
>> edit it i.e.

>> the line:

>> Library_Path=$MDR/ext/gfd/hort:$Library_Path:/ext/df1; export Library_path

>> and I want the output to be

>> Library_Path=$Library_Path:/ext/df1; export Library_Path.

>> That is I want to remove the "$MDR/ext/gfd/hort" from the line.

>> I have tried substituting but to no avail.

>> Thanks for any help in advance.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Tue, 13 Nov 2001 03:00:00 GMT  
 Replacing text within a line

Quote:

>Hi,

>if anyonje out there can help it would be gratefully appreciated.

>I have a file of text. Within that file I want to find a particular line and
>edit it i.e.

>the line:

>Library_Path=$MDR/ext/gfd/hort:$Library_Path:/ext/df1; export Library_path

>and I want the output to be

>Library_Path=$Library_Path:/ext/df1; export Library_Path.

>That is I want to remove the "$MDR/ext/gfd/hort" from the line.

You need to uniquely identify the line(s) that you want to
do the substituting on and the use the sub or gsub function.

Let's assume that lines stating with "Library_Path" uniquely
identify lines you want changed, then this will do the trick:

gawk '/^Library_Path/{gsub("$MDR/ext/gfd/hort","")};{print}' infile>outfile

read the man page

man gawk
man awk

you could also do this with sed, or other editors.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Wed, 14 Nov 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Search and replace text in a file based on a specific line

2. Replacing blank lines with text.

3. Replacing a line in a Text File

4. How to replace multiple-line text

5. Multiple line text input within a compiling word

6. NeedHelp : find a string within lines of text.

7. Text widget --screen lines vs. text lines

8. Centering Text Vertically Within Same Text Field

9. Tk bug? Text within text

10. Replacing a string from an input file within awk script

11. searching and replacing a string within a file with rexx

12. how to read text files line by line?

 

 
Powered by phpBB® Forum Software