shell script to edit file and delete entry


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script to edit file and delete entry
# 1  
Old 08-11-2008
shell script to edit file and delete entry

Can anyone provide me a shell script to edit a xml file and delete one entry.

To do manually i can edit(vi editor) the file and 'dd' will delete the file.But I wiluld to know if I can do with a script.

Thanks in advance
Tannu
# 2  
Old 08-11-2008
you can do it with sed but only advanced sed comes with -i option where you can delete
the required line and save the edited file...
but in normal sed you have to redirect the edited file to someother file...
just go through the man page of sed... and awk...
This User Gave Thanks to vidyadhar85 For This Post:
# 3  
Old 08-11-2008
Quote:
Originally Posted by tannu
Can anyone provide me a shell script to edit a xml file and delete one entry.

To do manually i can edit(vi editor) the file and 'dd' will delete the file.But I wiluld to know if I can do with a script.

Depending on the format of the file, it can be done with sed or awk (or a pure shell script). For example:

If the entry is all on one line:

Code:
sed '/<entry>..</entry>/d' FILENAME

If it's on more than one line with nothing else on those lines:

Code:
sed '/<entry>/,</entry>/d' FILENAME

# 4  
Old 09-05-2008
Hi
Thanks for your reply.
Actually the xml file looks like
#vi package.xml
<rpm>drivers-3.6.22-${release}.${arch}.rpm</rpm>
..
..
#
And if I want to delete this entry then what should be the sysntax?

I tried
Code:
sed '/<rpm>drivers-3.6.22-${release}.${arch}.rpm</rpm>/d' /root/packages.xml

but i did't worked.Can you please let me know.

Appreciate your help.

Last edited by Yogesh Sawant; 03-29-2010 at 04:09 PM.. Reason: added code tags
# 5  
Old 09-05-2008
Quote:
Originally Posted by tannu
I tried " sed '/ <version>3.2</version> /d'/root "

but i did't worked.Can you please let me know.

You need to escape the slash in the pattern:

Code:
sed '/ <version>3.2<\/version> /d'   FILENAME

# 6  
Old 09-08-2008
Hi

Thanks.

But it copies everything to output file that is package.xml to output.txt.
Code:
sed '/<rpm>driver-block-cciss-3.0.14-${release}.${arch}.rpm<\ /rpm> /d' /root/package.xml > /root/output.txt

Thanks for your help.

Last edited by Yogesh Sawant; 03-29-2010 at 04:08 PM.. Reason: added code tags
# 7  
Old 09-09-2008
Hi

Thankyou so much it worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. How to Post in the The UNIX and Linux Forums

Help me, write a bash script to delete parent entry with all their child entry in LDAP UNIX server

Hi All, Please help me and guide me to write a bash/shell script on Linux box to delete parent entry with all their child entries. example: Parent is : ---------- dn: email=yogesh.kumar@wipro.com, o=wipro, o=in child is: ---------- dn: cn: yogesh kumar, email=yogesh.kumar@wipro.com,... (1 Reply)
Discussion started by: Chand
1 Replies

2. Homework & Coursework Questions

Edit the file in shell script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to automate hadoop installation procedure using shell script. It involves go to perticular directory... (3 Replies)
Discussion started by: Abdul Navaz
3 Replies

3. Shell Programming and Scripting

How to update an entry of another file in a Shell script?

Hi all, Say I have a shell script called update_password.sh - in this script I want to perform a task to update a specified entry of another file (e.g. users.passpords) update_password.sh #!/bin/bash -e PW_FILE_DIR="${A_DIR}/.../..." PW_FILE="users.passwords" I want to update the... (2 Replies)
Discussion started by: isaacniu
2 Replies

4. Shell Programming and Scripting

shell script to edit a file

i have a file called number which contains data as 1 2 3 4 5 6 7 8 9 0 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 needed a shell script to print the output as 1 7 7 1 4 and (2 Replies)
Discussion started by: jacky29
2 Replies

5. Shell Programming and Scripting

How to edit file to have one line entry?

Hello All, My file content is: DROP TABLE "FACT_WORLD"; CREATE TABLE "FACT_WORLD" ( "AR_ID" INTEGER NOT NULL, "ORG_ID" INTEGER NOT NULL ) DATA CAPTURE NONE COMPRESS YES; I want to change this file to have entries in one... (6 Replies)
Discussion started by: akash2508
6 Replies

6. Shell Programming and Scripting

Shell script to edit a file

Hello, I have a big file in wich I would like to rename inside this exactly the string '_ME' and not rename in case we have 'ABC_MELANGE'. Is there a way to do it by using a shell script? Any tip will be apreciated. The file is like described bellow, after using command more filename : ... (3 Replies)
Discussion started by: Titas
3 Replies

7. Shell Programming and Scripting

Edit date entry inside a file

Hi All, I wanted to edit the date value located at /var/opt/CPsuite-R65/fw1/conf/local.scv. The date entry looks like this : :Signature (">=20100717") How can I update the date value by 1 day every other day while preserving the margins of the whole file in a shell script? I have... (5 Replies)
Discussion started by: achillesxv
5 Replies

8. Shell Programming and Scripting

Edit a config file using shell script

I need to edit a config file using shell script. i.e., Search with the 'key' string and edit the 'value'. For eg: below is what I have in the config file "configfile.cfg". Key1=OldValue1 Key2=OldValue2 I want to search for "Key1" and change "OldValue1" to "NewValue1" Thanks for your... (7 Replies)
Discussion started by: rajeshomallur
7 Replies

9. Shell Programming and Scripting

shell script to edit the content of a file

Hi I need some help using shell script to edit a file. My original file has the following format: /txt/email/myemail.txt /txt/email/myemail2.txt /pdf/email/myemail.pdf /pdf/email/myemail2.pdf /doc/email/myemail.doc /doc/email/myemail2.doc I need to read each line. If the path is... (3 Replies)
Discussion started by: tiger99
3 Replies

10. AIX

How to edit txt file by shell script?

What I want to do is just delete some lines from a text file, I know it's easy using copy and redirect function, but what I have to do is edit this file (delete the lines) directly, as new lines may be added to the text file during this period. Can AIX do this ? # cat text 1:line1 2:line2... (3 Replies)
Discussion started by: dupeng
3 Replies
Login or Register to Ask a Question