Removing and copying in shellscript


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing and copying in shellscript
# 1  
Old 09-16-2011
Removing and copying in shellscript

Hi,
I need to edit an xml file as such
Code:
<B="A"><![C]]></B>

so that the output is
Code:
<A><![C]]></A>

This is a massive xml file and the A B and C are always different however the output should always be the same.

Does anyone know any solution to this please?

thanks in advance

Last edited by vbe; 09-16-2011 at 11:51 AM..
# 2  
Old 09-16-2011
Hi,

I don't know if it will work with more complex files. Your example seems to simple, but give it a try:
Code:
$ cat infile
<B="A"><![C]]></B>
$ cat script.pl
use warnings;
use strict;

while ( <> ) {
        chomp;
        s#^[^"]+"([^"]+)">(<!\[[^]]+\]\]>).*$#<$1>$2</$1>#;
        printf "%s\n", $_;
}
$ perl script.pl infile
<A><![C]]></A>

Regards,
Birei
# 3  
Old 09-16-2011
Code:
echo '<B="A"><![C]]></B>' | sed 's/<.="\(.\)">\(.*\)<.*/<\1>\2<\1>/g'

Like Birei said, will fail for complex patterns!

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

2. Shell Programming and Scripting

Help with shellscript

I am new in shell script i want to convert .txt file in the format axsjdijdjjdk to a x s j d i j d j j d k (5 Replies)
Discussion started by: sreejithalokkan
5 Replies

3. Post Here to Contact Site Administrators and Moderators

help with backup shellscript

can any one advice on this.. create archive backup -yyyymmdd.tr.gzin the directory "backup" that includes the following directory " product/dev","product/uat"and product/maintain", yymmdd, stand for current date This archive needs to be perpared at 9PM every day Thanks advance (1 Reply)
Discussion started by: ksakil
1 Replies

4. Shell Programming and Scripting

if condition in shellscript

Hi All, I tried below code getting error. AD=0 ZERO=0 if then echo "AD is zero select another symbol" fi syntax error near unexpected token `fi' plz help me to solve this error (4 Replies)
Discussion started by: aish11
4 Replies

5. Shell Programming and Scripting

Backup script: Copying and removing directories based on list

I am writing a simple backup script, but I cannot figure out how to remove directories that are found in a list. For example: DONT_COPY=" .adobe/ .bin/google-earth " tar -zcvf - * --exclude=$DONT_COPY | openssl des3 -salt -k $1 | dd of=$(hostname)-$(date +%Y%m%d).tbz > COPIED Note that... (4 Replies)
Discussion started by: dotancohen
4 Replies

6. Shell Programming and Scripting

Need help with shellscript

Hello. I am a novince at writing shell scripts but here is the question. I have to write a shell script that does the following: Once executed via crontab, the script should do the following: a. get date/time stamp in for format 10-MAR-05 and b. execute shell script my_script.sh (which... (2 Replies)
Discussion started by: jigarlakhani
2 Replies

7. Shell Programming and Scripting

Another shellscript question

Folks; on a unix server I have a mapping file which holds a list mountpoints of all databases and their mountpoints. tab delimited or colon deliminted..I needed to copy the datafiles from the pristine mountpoints to test's mountpoints in this case. I needed to do this by passing sid name using... (18 Replies)
Discussion started by: jigarlakhani
18 Replies

8. UNIX for Advanced & Expert Users

ftp in Shellscript

Can I do something like this from a shellscript ?: ftp 12.34.56.78 <<! username password put a.c bye ! It does not go through as the login fails. Is there any alternative to do the above requirement? Thanks in advance. Gowrish (3 Replies)
Discussion started by: ggowrish
3 Replies
Login or Register to Ask a Question