Sponsored Content
Top Forums Shell Programming and Scripting Help with sed matching <tag1> newline spaces <tag2> and replace the value in the same string format Post 302419537 by albertogarcia on Friday 7th of May 2010 12:37:00 PM
Old 05-07-2010
Hello,
I don't know if the next is a solution...

Code:
tratar_linea=0  # false
echo "" > $new_file

while read line
do
   new_line="$line"
   if [ $tratar_linea -eq 1 ]
   then
       echo $line | grep '<tag2>' > /dev/null
       if [ $? -eq 0 ]
       then
          new_line="<tag2>new value you want</tag2>"
       fi
   fi

   echo $line | grep '<tag1>' > /dev/null
   if [ $? -eq 0 ]
   then
      tratar_linea=1
   else
      tratar_linea=0
   fi

   echo $new_line >> $new_file
done < xml_file_you_have

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed: replace string with another string (with spaces)

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)
Discussion started by: zmfcat1
4 Replies

2. 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

3. Shell Programming and Scripting

Replace a string with newline

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)
Discussion started by: my_Perl
1 Replies

4. UNIX for Dummies Questions & Answers

replace text string with a newline

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)
Discussion started by: aaronpoley
1 Replies

5. Shell Programming and Scripting

Using sed I want to replace space by newline

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)
Discussion started by: RahulJoshi
5 Replies

6. Shell Programming and Scripting

sed to replace the matching pattern with equal number of spaces

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)
Discussion started by: rakeshkumar
8 Replies

7. Shell Programming and Scripting

Replace String With Newline

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)
Discussion started by: Ste_Moore01
15 Replies

8. Shell Programming and Scripting

How to replace NewLine with comma using sed?

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)
Discussion started by: Ajaypal
8 Replies

9. Shell Programming and Scripting

Replace newline in a string

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)
Discussion started by: Pratik4891
8 Replies

10. UNIX for Dummies Questions & Answers

Replace string including newline

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)
Discussion started by: ngb
5 Replies
BINSRCH(3)						    WordNettm Library Functions 						BINSRCH(3)

NAME
bin_search, copyfile, replace_line, insert_line - general purpose functions for performing a binary search SYNOPSIS
char *bin_search(char *key, FILE *fp); void copyfile(FILE *fromfp, FILE *tofp); char *replace_line(char *new_line, char *key, FILE *fp); char *insert_line(char *new_line, char *key, FILE *fp); DESCRIPTION
The WordNet library contains several general purpose functions for performing a binary search and modifying sorted files. bin_search() is the primary binary search algorithm to search for key as the first item on a line in the file pointed to by fp. The delim- iter between the key and the rest of the fields on the line, if any, must be a space. A pointer to a static variable containing the entire line is returned. NULL is returned if a match is not found. The remaining functions are not used by WordNet, and are only briefly described. copyfile() copies the contents of one file to another. replace_line() replaces a line in a file having searchkey key with the contents of new_line. It returns the original line or NULL in case of error. insert_line() finds the proper place to insert the contents of new_line, having searchkey key in the sorted file pointed to by fp. It returns NULL if a line with this searchkey is already in the file. NOTES
The maximum length of key is 1024. The maximum line length in a file is 25K. If there are no additional fields after the search key, the key must be followed by at least one space before the newline character. SEE ALSO
wnintro(3), morph(3), wnsearch(3), wnutil(3), wnintro(5). WARNINGS
binsearch() returns a pointer to a static character buffer. The returned string should be copied by the caller if the results need to be saved, as a subsequent call will replace the contents of the static buffer. WordNet 3.0 Dec 2006 BINSRCH(3)
All times are GMT -4. The time now is 11:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy