Sponsored Content
Top Forums Shell Programming and Scripting sed: replace string with another string (with spaces) Post 302333652 by TonyFullerMalv on Monday 13th of July 2009 05:45:29 PM
Old 07-13-2009
Code:
sed -e 's/XABCD/This is the first string/g' -e 's/XEFGHX/This is the second string/g' -e 's/XIJKLX//This is the third string/g' XMLFILE > XMLFILE.$$ && \
cp XMLFILE.$$ XMLFILE && \
rm XMLFILE.$$

would do the trick but would get cumbersome if you had say 99 different strings you wanted to substitute, I'm sure a scripting guru my come up with something more elegant!
 

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

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: <recipients> <member>value1</member> </recipients> I need to find a string <recipients> that follows with a new-line and bunch of spaces and... (5 Replies)
Discussion started by: mgharios
5 Replies

3. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

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

5. Shell Programming and Scripting

String replace that has spaces

cat rf|nawk '/Use SSL= 0/{n+=1}{if (n==3){sub("Use SSL= 0","Use SSL= 0x1",$0)};print }' > rf2Fails. sed 's/Use SSL= 0/Use SSL= 0x1/g' rf > rf2Fails. In addition, the goal is to ONLY replace the 2nd occurence of the... (15 Replies)
Discussion started by: rfransix
15 Replies

6. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

7. Shell Programming and Scripting

How to find and replace a string with spaces and / recursively?

Hi all, I wanted to find and replace an email id from entire directory structure on a Linux server. I found that find . -type f -print0 | xargs -0 sed -i 's/abc@yahoo.com/xyz@gmail.com/g' would do it perfectly. But my search criteria has extended and now I want to search for a string1 like... (2 Replies)
Discussion started by: pat_pramod
2 Replies

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

9. UNIX for Dummies Questions & Answers

How do I replace a string in file that is in a certain position with spaces?

I am trying to replace the string in position 26 through 35 of the data file with 10 spaces and I want the remaining file to stay as is, the record length is over 900 characters? I am trying to use the AWK and substr but I am not getting it formatted correctly. Before... (6 Replies)
Discussion started by: fnwine1500
6 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
ctypeslib(1)							   User Commands						      ctypeslib(1)

NAME
h2xml - convert header files to XML intermediates xml2py - convert XML intermediates to Python ctypes interface SYNOPSIS
h2xml includefile ... [options] -o outputxmlfile xml2py xmlfile ... [options] -o outputpyfile DESCRIPTION
ctypeslib is a Python code generator capable of converting C header files into xml files (using gccxml), and then converting the xmlfiles into Python modules which define a ctypes interface to the corresponding C library. Ctypeslib is not ctypes. Ctypes is included in Python 2.5+ and as an add-on for lower versions, while ctypeslib is a lesser known add-on written by the ctypes author. If you use ctypes a lot and are tired of setting argtypes and restype of the called functions, you should look into ctypeslib. Ctypeslib can also set up data types and structures from C header files automatically. h2xml and xml2py are the user interface scripts to ctypeslib. h2xml converts C header files into xml intermediates (using gccxml) and xml2py converts these intermediates to Python files. At the minimum, you can get automatic construction of the C types (structures, etc) in ctypes definitions. With extra options, macro definitions can be expanded and the output Python file can be automatically linked (using ctypes) to the corresponding C library. The briefest example is: h2xml header.h -o out_c.xml xml2py out_c.xml -o out_c.py To obtain preprocessor symbols, you must use the -c flag to h2xml. To automatically link to C libraries via ctypes, you muss pass the rel- evant libraries to xml2py with -l library.so. OPTIONS
h2xml options: -h, --help show brief help message -q, --quiet -D NAME[=VALUE] macros to define -U NAME macros to undefine -I DIRECTORY additional include directories -o XMLFILE XML output filename -c, --cpp-symbols try to find #define symbols - this may give compiler errors, so it's off by default. -k don't delete the temporary files created (useful for finding problems) xml2py options: -h, --help show this help message and exit -c include source file location in comments -d include docstrings containing C prototype and source file location -k TYPEKIND kind of type descriptions to include: d = #defines, e = enumerations, f = functions, s = structures, t = typedefs -l DLLS libraries to search for exported functions -o OUTPUT output filename (if not specified, standard output will be used) -r EXPRESSION regular expression for symbols to include (if neither symbols nor expressions are specified,everything will be included) -s SYMBOL symbol to include (if neither symbols nor expressions are specified,everything will be included) -v verbose output -w add all standard windows dlls to the searched dlls list -m module Python module(s) containing symbols which will be imported instead of generated --preload=DLL dlls to be loaded before all others (to resolve symbols) EXAMPLES
Please see /usr/share/doc/python-ctypeslib/examples.Debian for examples and explanation. SEE ALSO
/usr/share/doc/python-ctypeslib/examples.Debian contains a brief tutorial on some key features Python docstrings (pydoc ctypeslib) Ctypeslib upstream is http://python.net/crew/theller/ctypes/ (see "Related Projects"). For ctypes information, see http://docs.python.org/library/ctypes.html AUTHOR
ctypeslib was written by Thomas Heller <theller@ctypes.org>. This manual page was written by Richard Darst <rkd@zgib.net>, for the Debian project (and may be used by others). ctypeslib March 2010 ctypeslib(1)
All times are GMT -4. The time now is 11:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy