Help with sed matching <tag1> newline spaces <tag2> and replace the value in the same string format
Hi, I'm very new to shell scripting and have searched google and this forum for quite some time now.
I have the following in my xml file:
I need to find a string <recipients> that follows with a new-line and bunch of spaces and <member>blah blah, i.e.
And I need to replace it in the same format, i.e.
There are exactly 8 spaces in front of the <member> tag but I'd like to avoid doing matching on # of spaces.
Here's what I've tried so far:
the final string looks like this:
--the opening tag <recipients> gets deleted, which makes sense based on what i put in the sed command, I guess.
--the final string looks like this:
-- again, makes sense based on the sed command but I just don't know how I can preserve the format of the string and look for <recipients> \n spaces <member> and replace it with the same string , just with different value.
I have originally tried using '/' instead of # as a seprator char, but switched to # becuase the value1 I'm looking to replace may contain a bunch of special chars, including '/' slash.
At this point I'm not even sure this can be done with sed? Should I try using "awk" or even perl, maybe?
Any help is greatly appreciated!
Last edited by Franklin52; 05-07-2010 at 04:05 PM..
Reason: Please use code tags!
The following approach is fine if you are going to hardcode "NEWVALUE" into the replacement text.
If instead it needs to be parameterized (if so, you should always mention that when requesting assistance), then you would need to make sure that NEWVALUE cannot include characters which are special in replacement text (such as the s command's delimiter, &, \, etc). In such a case, it would probably be safest to use AWK and its string handling functions (index, substr, length, and their ilk).
Thank you alister. I don't need to parameterize the replacement string so this solution is exactly what I was looking for. And thanks for clarification on N.
Hi,
I am trying to do some transformation on a large file and I am getting some troubles trying remove newlines only when the last character of a line is a symbol (in this case is a pipe "|").
I have tried with sed like this:
sed -i 's/|\n/|/g' my_file
or
sed -i 's/|$/|/gg' my_file... (5 Replies)
I have a string like below:
{\rtf1\fbidis\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}{\f1\fnil MS Sans Serif;}}
\viewkind4\uc1\pard\ltrpar\lang2057\f0\fs16 19/11/2010 SOME DESCRIPTION. \par
\lang1033\f1\par
}
I have to replace the newline character with null in the... (8 Replies)
Hi ,
I have a huge file with following records and I want to replace the last comma with ',NULL'. I try using SED but could not create a correct script .
In my opinion I need a script which can convert ,/n with ,NULL/n
1,CHANGE_MEMBER,2010-12-28 00:05:00,
2,CHANGE_MEMBER,2012-09-02... (8 Replies)
Hi,
I'm struggling with a string replacement.
I have an XML file which is in the following layout
<FUNCTION>
<PRODUCTS>
<PRODUCT CODE="PRODUCE" ACTION="amend" VALIDATE="no">
<SUPPLIER PRODUCT="PRODUCT" ACTION="amend" CODE="SUPPLIER">
<STOCK_QUANTITY DATA="21"/>
... (15 Replies)
Hi
I have written a shell script which used sed code below
sed -i 's/'"$Pattern"'/ /g' $FileName
I want to count the length of Pattern and replace it with equal number of spaces in the FileName.
I have used $(#pattern) to get the length but could not understand how to replace... (8 Replies)
Input:
--------------------------
123asd 456sdasda 789a
-------------------------
output wanted:
---------------------
123asd
456sdasda
789a
----------------------
I want this by sed in simple way
please help (I know by: tr ' ' '\n' < inputfile )I want it by sed only (5 Replies)
I want to replace a text string with a newline. I have a long text file of random characters. I want to replace all the occurences of "pe" with a newline. How can I do that in Unix? There's a thread from 2004 saying that you can do something like this with sed by actually pressing the return... (1 Reply)
Hi all
I have the problem to substitute a string with newline in Perl. Can anybody help me?
And also how to replace a string with opening bracket (e.g. (START ) with a whitespace/null character?
Thanks in advance. (1 Reply)
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)
Hi
I have an XML file with strings XABCD, XEFGHX and XIJKLX. I would like to replace XABCDX with "This is the first string", XEFGHX with "This is the second string" and XIJKLX with "This is the third string".
What is the best way to implement this? Should I have a file with the data that is... (4 Replies)