sed to remove partial text in one line only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed to remove partial text in one line only
# 1  
Old 10-12-2014
sed to remove partial text in one line only

I have test.xml XML file like

Code:
<Report account="123456" start_time="2014-09-08T00:00:00+00:00" end_time="2014-09-10T23:59:59+00:00" user="Dollar Tree" limit="1000000" more_sessions="some text ">
<Session ......rest of xml...............

I need output like

Code:
<Report>
<Session ......rest of xml...............

Can some one help me how to use of SED command to get the desired output..

Last edited by Don Cragun; 10-12-2014 at 07:39 PM.. Reason: Add CODE tags.
# 2  
Old 10-12-2014
Code:
sed -e 's/\(<Report\)[^>]*/\1/'

# 3  
Old 10-12-2014
Hi,

Thanks for your reply..I have tried below command

Code:
sed -e 's/\(<Report\)[^>]*/\1/' test.xml

but i cannot see the output as

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Report>
<Session ...>

The report tag description is not deleting ....I can see the same old output as

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Report account="123456" start_time="2014-09-08T00:00:00+00:00" end_time="2014-09-10T23:59:59+00:00" user="Dollar Tree" limit="1000000" more_sessions="some text ">
<Session ......rest of xml...............

Moderator's Comments:
Mod Comment Please use CODE tags for sample input, output, and code segments as required by forum rules.

Last edited by Don Cragun; 10-12-2014 at 10:06 PM.. Reason: Add CODE tags.
# 4  
Old 10-12-2014
Code:
sed -e 's/^<Report.*$/<Report>/'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to update file with partial matching line in another file and append text

In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. UNIX for Beginners Questions & Answers

How can I remove partial duplicates and manipulate text?

Hello, How can I remove partial duplicates and manipulate text in bash using either awk, grep or sed? Thanks. Input: ted,"foo,bar,zoo" john-son,"foot,ben,zoo" bob,"bar,foot" Expected Output: foo,ted bar,ted zoo,ted foot,john-son ben,john-son (4 Replies)
Discussion started by: tara123
4 Replies

3. Shell Programming and Scripting

sed to remove text from file

Trying to use sed to, in-place, remove specific text from a file. Since there are / in the text I use | to escape that character. Thank you :). sed -i -e 's|xxxx://www.xxx.com/xx/xx/xxx/.*/|' /home/cmccabe/list sed: -e expression #1, char 51: unterminated `s' command (4 Replies)
Discussion started by: cmccabe
4 Replies

4. Shell Programming and Scripting

Remove text with sed or anything?

Hi there, my first post, so you might find my noobness ;) I need help to fix a thing, find /mnt/fs01/gfx/ -iname "*.rar" > gfx.txt Gives this contained textfile: /mnt/fs01/gfx/toba/toba.rar /mnt/fs01/gfx/zeta/zimba.rar /mnt/fs01/gfx/brashe/getha.rar And now the tricky part (for... (3 Replies)
Discussion started by: yabbah
3 Replies

5. UNIX for Dummies Questions & Answers

How To Use sed To Remove Text Between '/*'?

First of all let it be said that I hate sed. Every time I think I've got it figured out it proves me wrong. There, now with that out of the way here's my problem that I'm hoping one of you smart people can solve: I have a file full of lines like this: If x=1 then /* this is an if statement */... (10 Replies)
Discussion started by: Korn0474
10 Replies

6. UNIX for Dummies Questions & Answers

Sed to remove only first line erroneously removes last line too

Hello everyone, This is my first posting. I have read the rules of this forum. I have searched many various threads and haven't found one that applies to my situation or suggestions to fix the issue. I do appreciate the help. I am trying to execute a basic UNIX script in a Solaris... (4 Replies)
Discussion started by: dqrgk0
4 Replies

7. Shell Programming and Scripting

AWK - Print partial line/partial field

Hello, this is probably a simple request but I've been toying with it for a while. I have a large list of devices and commands that were run with a script, now I have lines such as: a-router-hostname-C#show ver I want to print everything up to (and excluding) the # and everything after it... (3 Replies)
Discussion started by: ippy98
3 Replies

8. Shell Programming and Scripting

sed to remove 1st two characters every line of text file

what is the sed command to remove the first two characters of every line of a text file? each line of the text file has the same amount of characters, and they are ALL NUMERIC. there are hundreds of lines though. for example, >cat file1.txt 10081551 10081599 10082234 10082259 20081134... (20 Replies)
Discussion started by: ajp7701
20 Replies

9. Shell Programming and Scripting

sed remove last 10 characters of a line start from 3rd line

hello experts, I need a sed command that remove last 10 characters of a line start from 3rd line. any suggestions? Thanks you (7 Replies)
Discussion started by: minifish
7 Replies

10. Shell Programming and Scripting

SED help (remove line::parse again::add line)

Aloha! I have just over 1k of users that have permissions that they shouldn't under our system. I need to parse a provided list of usernames, check their permissions file, and strip the permissions that they are not allowed to have. If upon the permissions strip they are left with no permissions,... (6 Replies)
Discussion started by: Malumake
6 Replies
Login or Register to Ask a Question