General :: Using Sed To Replace String With Special Characters In XML File?
Apr 29, 2011
I am having difficulty getting sed to replace a string of text in an XML file, despite the fact that I have no trouble using grep to find that same string. Since the new string and old string to be replaced contain a lot of special characters, I thought it best to store them in variables as opposed to using a slew of backslashes:
OLD_STRING='<property name="webServiceHost">${jboss.bind.address}</property>'
NEW_STRING='<!--<property name="webServiceHost">${jboss.bind.address}</property>-->'
[Code]....
View 2 Replies
ADVERTISEMENT
Aug 26, 2009
Below is extract of my file:
What I need is to replace "--destination-path=" with "--destination-path=/home/dest"
i.e. desired output is ----destination-path=/home/dest
I could achieve it with below command
$cat outgoing-xfer|grep destination-path|perl -pi -e "s/destination-path=/destination-path=/home/dest/g"
But the problem is that in this case i just wanted to append "/home/dest" for which I could easily escape "/" with just two "", but I wonder if i have a long path like "/a/b/c/d/e/f/g/h/i/j" I will have to escape so many /. Is there any other way by which I can avoid escaping forward slash.
I tried following:
But receiving follo error
Bareword found where operator expected at -e line 1, near "s/destination-path=/'destination-path=/home"
syntax error at -e line 1, near "s/destination-path=/'destination-path=/home"
Bad name after dest' at -e line 1. tried with enclosing in double quotes as well but in vain
View 5 Replies
View Related
Mar 24, 2011
I have a file with special characters that need to be replaced. I've been working on this for a day and have run out of time.
Example: FILE='/var/tmp/S0000000.LOG.March-24-2011:10:51.tar'
Need to replace the ' with a " on all lines in the file.
View 2 Replies
View Related
Feb 6, 2011
I wish to replace a new line with br (html) but it doesn't seem to work
Code:
message=$(echo ${FORM_message} | tr '
' '<br />' )
what it gives me seems to be ... b...? I am also having problem escaping hash sign in cut command:
Code:
list=$(echo "$line" | cut -d'#;#' -f1) ;
my intention is to split the line with "#;#"
View 5 Replies
View Related
Jan 4, 2011
here's my newbie question - I want to change the following string in text files
Code:
E:MP3
with the following string using sed:
[code]....
View 3 Replies
View Related
Jan 30, 2011
I am reading strings from a file using readline() function,the file contains some strings which has only special characters, I need to avoid the strings which has only special characters, the special characters are not similar. How to do it in python.??
View 2 Replies
View Related
May 21, 2010
Simple logging script that allows user to enter quick notes and questions, but I can not get it to pass punctuation '?. no matter what I type after 'n' i need that to be inserted at the end of the working project note file.Any help and working examples would be appreciated, but please also direct me to the proper reading material so I can learn something - not looking for someone to just do it for me.usage:
Code:
bob@smith:~/notes$ n bob's script sucks?
>
[code]....
View 14 Replies
View Related
Feb 20, 2010
I am running gentoo openbox(rox file manager and desktop) I installed Digikam and Amarok. But I have problems with files which include special character in their names(such as �,�, �,ğ... ) The files are shown with strange and weird characters in the file dialogs of Digikam and Amarok.
I don't have this problem in other applications. I can create files with special character included. I think some settings do not agree with KDE4. How can I solve this problem? Does anyone have an idea? I also installed KDE systemsettings program but could not find a relevant config option for character encoding.
View 2 Replies
View Related
Sep 2, 2010
We're in the process of implementing an offsite backup of all our servers to a remote Linux server. We're using rsync over ssh.What I've found is that characters such as ±, ¶,´ and £ are replaced on the Linux server with underscores.I don't mind if it changes these characters in the filenames of documents, but when it renames a language pack from Espa±ol.clx to Espa_ol.clx, it could cause issues for us further down the line.
What do I need to do differently to make the special characters copy over correctly? For the initial sync which will take place locally, before the machine is moved offsite, I have SAMBA enabled. I am able to copy files from Windows to the Samba share, retaining the original filename, though it looks different in the Linux directory listing, i.e. t̻st becomes ĻstThese files get deleted by rsync when it runs, as it does not match the filenames.
View 1 Replies
View Related
Nov 7, 2010
I have txt file with list of ID's and I need to insert comma in every line and then remove new line character so it'll become one long string. So to clarify, I have txt file content that looks like this.
234
5466
2356
... and so on.
but I would like this to change to 234,5466,2356,... I looked at sed and tried to wrap my head around the commands but I guess my brain isn't smart enough. its really confusing for me. I've managed to add commas to end of line (sed "s/$/,/g" filename) but somehow I can't seem to remove new line character from each line.
sed 's/[
]*$//' doesn't seem to work.
View 4 Replies
View Related
Sep 2, 2010
I have a line in a text file that has 40 random characters within a tag and i want to change the characters to a new set of 40 random characters (alphanumeric a-z 0-9 etc)
The line in the text file looks like this:
Quote:
How would i go about doing that?
Also second question same as the above but how would i remove them instead of replacing them?
View 14 Replies
View Related
Apr 26, 2011
If I have a word in a text file and I need to replace it by another word (for example, i need to replace abc by fff) so what is the command I can type it?
I am using vi editor.
View 3 Replies
View Related
Aug 31, 2010
Need to replace the following string :
By
In multiple .exp files and in sub directories.
View 5 Replies
View Related
May 20, 2010
I have large text files with space delimited strings (2-5). The strings can contain "'" or "-". I'd like to replace say the second space with a pipe. What's the best way to go?
Using sed I was thinking of this:
sed -r 's/(^[a-z'-]+ [a-z'-]+) /1|/' filename.txt
View 2 Replies
View Related
Feb 26, 2010
I need to replace a string in a file(startup.sh) using a script(parser.sh). After running parser.sh startup.sh should be filled with nfs path like /home/vimal etc but im getting error since path contains /. how to remove this.
View 3 Replies
View Related
Jan 26, 2011
I'm having issue when trying to change a line in a file
[Code]....
View 1 Replies
View Related
Apr 2, 2011
I want to replace a string of directory path in a string to empty:
Code:
But this doesnt seem to give me the desired thing:
Code:
This gives the desired outcome, but its specific, i need a variable in the sed not a string. And if I replace STRING="/mnt/sda1/record/$dd/" then I cant use it for something else, cause its has all the weird backslashes now.
View 3 Replies
View Related
May 25, 2011
I want to be able to enter special characters into OOWriter and gedit. Ubuntu supports UTF-8, and I've no idea how to use it.
View 1 Replies
View Related
Jan 21, 2011
I am trying to make specifically Norwegian characters appear properly. Right now they look like this:
[URL]
Characters like turns the same. This is a font that I downloaded called PT Sans. The letters I want are included, they just don't appear right in the GNOME environment, it seems. They work just fine in other applications, such as OOo Writer. I'm using Ubuntu 10.04.
View 7 Replies
View Related
Jun 1, 2010
I want to archive all .ctl files in a folder, recursively.tar -cf ctlfiles.tar `find /home/db -name "*.ctl" -print`The error message :tar: Removing leading `/' from member namestar: /home/db/dunn/j: Cannot stat: No such file or directorytar: 74.ctl: Cannot stat:No such file or directoryI have these files: /home/db/dunn/j 74.ctl and j 75. Notice the extra space. What if the files have other special characters? How do I archive these files recursively?
View 2 Replies
View Related
Apr 15, 2009
I've always been connecting to linux machine from windows computer, using putty.
Now the situation changed and I have a question:
How the hell can I write special characters (like | ~ Alt + 124 in Windows)?
View 4 Replies
View Related
Apr 13, 2011
We are creating PDFs from different sources using PHP, Zend_PDF class and Zend server (based on apache2). Developping on windows the PDFs are OK. If we deploy the application on testing server running SuseLinux the special characters ( ) don't show. We use 1 of the standard fonts, HELVETICA and have tested without success COURIER.
The system
Do you have an idea what to do or try?
OK - it turned out to be a coding question. I had thought that some system variable might cause the problem but we simply had to clean the input data and got it working.
View 1 Replies
View Related
Feb 10, 2010
I need to search for the following pattern with GREP in a text file:
So I tried already:
But none of those works...I think probably because GREP doens't like the special character > in the middle of the serach pattern.
At the end I just need to now if GREP found the pattern in the file or not, so it should give me a 0 or a 1 back, once I check the value of the variable "?" after using the grep command.
View 4 Replies
View Related
Jun 5, 2011
The command tar -xvf wpa_tables.tar gives this error
tar: ./xai-0/334Regency: Cannot open: Invalid or incomplete multibyte or wide character
tar: Exiting with failure status due to previous errors
Obviously the backslash is giving tar some problem, but I've been all over the docs and can't figure out how to either make it skip this file or interpret the character literally. Here's my command history to show some of the options I've tried which don't work.
tar --no-wildcards -xkvf wpa_tables.tar
tar --exclude ./xai-0/\334Regency -xkvf wpa_tables.tar
tar --exclude "./xai-0/\334Regency" -xkvf wpa_tables.tar
tar --ignore-command-error -xkvf wpa_tables.tar
tar --ignore-failed-read -xkvf wpa_tables.tar
tar --transform 's/\/slash/g' -xvf wpa_tables.tar ./xai-0/\334Regency
I'm totally out of ideas at this point and would welcome some input from more experienced members.
View 1 Replies
View Related
Jun 30, 2011
I have an odd request, lets say I have a text file like this:
Quote:
Code:
__##___##___IIIIII
__##___##_____II__
__##___##_____II__
__#######_____II__
__##___##_____II__
__##___##_____II__
__##___##___IIIIII
I want a script that will replace all of the hash tabs with random characters.I found this command will generate a random character
Quote:
apg -a1 -n1 -m1 -x1 -d
how to script a search and replace using that random character upon each successive find until the end of file occurs.
View 9 Replies
View Related
Jul 28, 2009
I have script that I'm working on that updates a username in all the files that are called blah.inc for my framework. since i host a bunch of these web apps i need to do it to all of them. so I need to figure out how to update these files automagically with out me watching it to call vim every time. heres what I have so far
Code:
This finds the files but now i need to figure out how to do s/bob/fred/g on those files.
View 5 Replies
View Related
Feb 28, 2009
I've found some scripts that replaces a string in a file but it's not quite working for me.
And I'm trying to replace a tag in an xml file that looks like this
So I ran a command line like this perl -w -i -p -e "s/xmlns="'http://mydomain.org/replacethese.xsd'">/>/g" testfile.xml
And I get a error output
Search pattern not terminated at -e line 1.
Found the script from this blog [url]
View 7 Replies
View Related
Apr 5, 2010
I know how to replace a particular instance (say 3rd one) of a word in a line using sed based on the sed one-liners. However I would like to replace a particular instance of a word in the entire file.
For example, here is a file:
Code:
John
Betty
Jack
Ron
Jack
Paul
So now I would like to replace the second instance of Jack (in red color) with "Rob" (for example). Not quite sure how to do that? I tried couple of things from here but they did not work.
View 10 Replies
View Related
Jun 30, 2011
I have question about replacing a string in a file.
How can I replace the printerb's 10.1.1.1 to something else(10.1.1.2, for example) without replace printera's 10.1.1.1 accidentally?
I have tried perl -e -pi "s/10.1.1.1/10.1.1.2/g" /etc/hosts. but, perl replace both 10.1.1.1 to 10.1.1.2.
View 13 Replies
View Related
Jul 14, 2010
I've written myself a linux program "program" that does something with a regular expression. I want to call the program in the bash shell and pass that regular expression as a command line argument to the program(there are also other command line arguments). A typical regular expression looks like "[abc]_[x|y]".Unfortunately the characters [, ], and | are special characters in bash. Thus, calling "program [abc]_[x|y] anotheragument" doesn't work. Is there a way to pass the expression by using some sort of escape characters or quotation marks etc.?
(Calling program "[abc]_[x|y] anotheragument" isn't working either, because it interprets the two arguments as one.)
View 7 Replies
View Related