![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| deleting lines from multiple text files | vrms | Shell Programming and Scripting | 3 | 04-25-2008 12:01 PM |
| replacing new lines in all files of a directory containing old lines | rooster005 | Shell Programming and Scripting | 1 | 03-25-2008 03:38 PM |
| How to delete first 5 lines and last five lines in all text files | ragavendran31 | Shell Programming and Scripting | 10 | 02-21-2008 07:58 AM |
| Replacing text | chrchcol | Shell Programming and Scripting | 3 | 07-25-2006 01:30 PM |
| replacing text | ajaya | Shell Programming and Scripting | 2 | 04-12-2006 01:31 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Replacing lines in text files
Hi,
I have 2 sets of text files. I need to take a field from a certain line in set 1 and put it in the same place in set b. The line appears once per file, in different places but is a set format and has the unique word "ANTENNA" in it and is always 81 characters long. Example from set a: " 0.0000 0.0000 0.0000 ANTENNA: DELTA H/E/N" Example from set b " 0.2160 0.0000 0.0000 ANTENNA: DELTA H/E/N" The bold bit is the field I'm trying to change and will be a random float in both sets. I've been trying to do it like this: #!/bin/ksh old_line=`grep ANTENNA ./file1.txt` new_line=`grep ANTENNA ./file2.txt` sed "s/${old_line}/${new_line}/" file1.txt >tmp2 #substitute old line with new line in file 1 and output to tmp2 But this doesn't work, probably because I have forward slashes in my grep lines which sed interprets as some sort of regexp. How can I escape these when they are embedded in a variable? Am I quoting incorectly? Or is there a much better way? Jon |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|