Sponsored Content
Top Forums Shell Programming and Scripting replace (sed?) a single line/string in file with multiple lines (string) from another file?? Post 302515336 by 4dirk1 on Tuesday 19th of April 2011 11:52:01 PM
Old 04-20-2011
Quote:
Originally Posted by rdcwayx
Code:
sed  '/NOVEMBER/r file2.txt' file1.txt |sed '/NOVEMBER/d'

Hi Sir!

I have a similar scenario. I have an xml file which I compiled in unix and i send it out as an attachment which opens with excel. Now there are certain keywords (kw01)in the xml file which I wanted to replace with the contents of txt files having multiple lines.

So i tried your code above with this command:
sed '/kw01/r fatal_alerts.txt' template.xml | sed '/kw01/d' > test.xml

now when I sent out the output file 'test.xml' and open it via excel, the cell where 'kw01' is located is not replaced with the contents of 'fatal_alerts.txt'.

Is there a possible way to do this sir? Need your help badly. Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

2. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

3. Shell Programming and Scripting

replace a string with contents of a txt file containing multiple lines of strings

Hello everyone, ive been trying to replace a string "kw01" in an xml file with the contents of a txt file having multiple lines. im a unix newbie and all the sed combinations i tried resulted to being garbled. Below is the contents of the txt file: RAISEDATTIME --------------------... (13 Replies)
Discussion started by: 4dirk1
13 Replies

4. Shell Programming and Scripting

SED - Multiple String - Single Line

Would appear to me to be a farily simple question but having search all the threads I can't find the answer .. I just want sed to output the single line in a file that contains two string anywhere on the line.. e.g. currently using this command sed -n -e'/str1/p' -e '/str2/p' < file and... (3 Replies)
Discussion started by: flopster
3 Replies

5. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

6. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

7. Shell Programming and Scripting

sed or awk to replace a value in a certain line from another file containing a string

Hi experts, In my text file I have the following alot of lines like below. input.k is as follows. 2684717 -194.7050476 64.2345581 150.6500092 0 0 2684718 -213.1575623 62.7032242 150.6500092 0 0 *INCLUDE $# filename... (3 Replies)
Discussion started by: hamnsan
3 Replies

8. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

9. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

10. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies
STAG-PARSE(1p)						User Contributed Perl Documentation					    STAG-PARSE(1p)

NAME
stag-parse - parses a file and fires events (e.g. sxpr to xml) SYNOPSIS
# convert XML to IText stag-parse -p xml -w itext file1.xml file2.xml # use a custom parser/generator and a custom writer/generator stag-parse -p MyMod::MyParser -w MyMod::MyWriter file.txt DESCRIPTION
script wrapper for the Data::Stag modules feeds in files into a parser object that generates nestarray events, and feeds the events into a handler/writer class ARGUMENTS
-p|parser FORMAT FORMAT is one of xml, sxpr or itext, or the name of a perl module this is the class that parsers the input file(s) and generates stag events xml assumed as default -w|writer FORMAT FORMAT is one of xml, sxpr or itext, or the name of a perl module this is the class that catches the events thrown by the parser; it can be any class, but the class is typically a writer xml assumed as default -o|out FILE the writer will use this file (defaults to STDOUT) -e|errf FILE file to store parse error handler output -errhandler FORMAT/MODULE FORMAT is one of xml, sxpr or itext, or the name of a perl module all parse error events go to this module -r|root NODE_NAME if this is specified, NODE_NAME becomes the root of the stag tree, and anything that was previously the root is placed below this. this happens automatically if more than one file is parsed (because there can only be one tree root) -color Works only if the output handler is able to provide ASCII-colors (currently supported for itext and xml) SEE ALSO
Data::Stag This script is a wrapper for the method Data::Stag->parse() perl v5.10.0 2008-12-23 STAG-PARSE(1p)
All times are GMT -4. The time now is 04:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy