Sponsored Content
Top Forums Shell Programming and Scripting sed command to substitute contents from external file Post 302783791 by hanson44 on Thursday 21st of March 2013 03:03:50 AM
Old 03-21-2013
Seems to work here, and I'm pretty sure those are standard sed commands.

Code:
$ cat InputFile.txt
before
Parameters "CParameters"
after

$ cat TextToReplace.txt
aaa
bbb

$ sed -e '/Parameters "CParameters"/r TextToReplace.txt' -e "//d" InputFile.txt
before
aaa
bbb
after

$ sed -e '/CParameters/r TextToReplace.txt' -e "//d" InputFile.txt
before
aaa
bbb
after

You don't need to \ escape the "CParameters" double quotes, because inside the single quotes. I avoid those confusing \ characters if possible.

Any chance there is a tab character in the pattern? Maybe there is something about the pattern that is "funny" and is confusing us. You might try to find the pattern with grep first, to figure out the regular expression. Another option is to experiment with the final version above with simple pattern, verify that works, then move on to the longer pattern.
This User Gave Thanks to hanson44 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SED To insert Directory Contents to file

I am on a HP-UX machine I have a directory called "/u01/blobs" and the files look like this: ls -1 7398 7399 7400 I need to produce a comma delimited file with the following format: filename,location/filename i.e: 7398,/u01/blobs/7398 7399,/u01/blobs/7399 7400,/u01/blobs/7400 What... (3 Replies)
Discussion started by: NomDeGuerre
3 Replies

2. Shell Programming and Scripting

Convert contents of file to lower case with SED

Hi I what to add option to existing sed code to convert target file to lower case #!/bin/ksh SOURCE_DATA_DEST=/ora TARGET_DATA_DEST=/home/oracle/alexz TARGET_DB_SID=T102_test sed -e "s/REUSE/SET/g" \ -e "s/NORESETLOGS/RESETLOGS/g" \ T102_ccf.sql > target.sql Thanks (2 Replies)
Discussion started by: zam
2 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

using sed command to display contents where line numbers are stored in variables

if i want to display the contents of a file between say line number 3 and 10 then i use the following command sed -n '3,10p' filename if this 3 was contained in x and 10 was contained in y then how wud this command modified? sed -n '$x,$yp' filename does not work..please advise (2 Replies)
Discussion started by: arindamlive
2 Replies

5. Shell Programming and Scripting

sed substitute command -- need help

I am trying to do what I thought should be a simple substitution, but I can't get it to work. File: Desire output: I thought I'd start with a sed command to remove the part of the header line preceding the string "comp", then go on to remove the suffix of the target string (e.g. ":3-509(-)"),... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

6. Shell Programming and Scripting

sed - Replace string with file contents

Hello, I have two files: file1 and file2 file1 has the following info: --- host: "localhost" port: 3000 reporter_type: "zookeeper" zk_hosts: - "localhost:2181" file2 contains an IP address (1.1.1.1) What I want to do is replace localhost with 1.1.1.1, so that the... (4 Replies)
Discussion started by: Jay Kah
4 Replies

7. Shell Programming and Scripting

Sed: how to use file contents in replacement string

I want to replace a string by contents of file. I am trying the following sed command: cat sample | sed "s^<enter description here>^`cat details`^" But it is not working. a=`cat details` and using $a will not help since it will affect the whitespaces. What am I missing in the above sed... (5 Replies)
Discussion started by: anand_bh
5 Replies

8. Emergency UNIX and Linux Support

sed replace file contents by reading from another file

Hello, My input file1 is like this by tab-delimited chr1 mm10_knownGene stop_codon 3216022 3216024 0.000000 - . gene_id "uc007aeu.1"; transcript_id "uc007aeu.1"; chr1 mm10_knownGene CDS 3216025 3216968 0.000000 - 2 gene_id "uc007aeu.1"; transcript_id "uc007aeu.1"; ... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

9. Shell Programming and Scripting

Using sed's hold-space to filter file contents

I wrote an awk script to filter "uninteresting" commands from my ~/.bash_history (I know about HISTIGNORE, but I don't want to exclude these commands from my current session's history, I just want to avoid persisting them across sessions). The history file can contain multi-line entries with... (6 Replies)
Discussion started by: ivanbrennan
6 Replies

10. UNIX for Beginners Questions & Answers

sed read contents of file and print value another file

Trying to use sed to insert the contents of a file into the end of each line in another file file1 This is a line Here is another line This is yet another line Here is a fourth line file2 TEXT desired output This is a line TEXT Here is another line TEXT This is yet another... (6 Replies)
Discussion started by: jimmyf
6 Replies
sethead(1)						      General Commands Manual							sethead(1)

Name
       sethead - Set FITS or IRAF header keyword values

Synopsis
       sethead [-dknv][r letter] <FITS or IRAF file> kw1=val1 kw2=val2 ... kwn=valuen

Description
       Set parameters in the header of a FITS or IRAF image.  If the keywords do not already exist, they are added at the end of the header.  Val-
       ues are assumed to be numeric if they contain no alphabetic characters and right-aligned.  Otherwise they are left-aligned after the equals
       sign,  and padded by spaces to a minimum of 8 characters.  To set keywords in a list of files, substitute @<listfile> for the file names on
       the command line.  To set a lot of keywords, put them, one per line, in a file and substitute @<keylistfile> on the command line.  If two @
       commands  are  present,	the  program  will figure out which contains file names and which contains keywords.  Lines in a keyword list file
       which do not contain an = are ignored.

Options
       -h     Write HISTORY line into output header with sethead version, current date and time, and names of keywords set.

       -k     Write SETHEAD keyword into output header with sethead version, current date and time, and names of keywords set.	If a SETHEAD  key-
	      word already exists, move the old value to a HISTORY line before writing the new value

       -n     Write a new file with an added "e" before the extension.

       -r letter
	      Rename  existing keywords whose values are being reset by prepending the character "letter".  Drop the last character if the changed
	      keyword is already 8 characters long.

       -v     Print confirmations of each parameter setting

Web Page
       http://tdc-www.harvard.edu/software/wcstools/sethead.html

Author
       Doug Mink, SAO (dmink@cfa.harvard.edu)

6 July 2001							     WCSTools								sethead(1)
All times are GMT -4. The time now is 07:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy