Can someone please explain sed -n '/^$/!{s/<[^>]*>//g;p;}' filename

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Can someone please explain sed -n '/^$/!{s/<[^>]*>//g;p;}' filename
# 1  
Can someone please explain sed -n '/^$/!{s/<[^>]*>//g;p;}' filename

I came across this sed expression, and it does exactly what I want.
However I haven't got the faintest clue how it does it and thus do not feel capable of using it.

Can someone please explain how this expression works?
(I used it to remove html tags in a html file I was converting to text)

sed -n '/^$/!{s/<[^>]*>//g;p;}' filename

The more detail the more I love you :-)
Thanks heaps,
# 2  
Hi maximus73,

sed -n '        ## Disable printing by default.
/^$/!{            ## In lines with content...
s/<[^>]*>//g;    ## Remove all conten between '< ... >'. Apply it many times for each line.
p;                ## Print line.
}' filename        ## File to process.

This User Gave Thanks to birei For This Post:
# 3  
The way I see it is, this would remove all the tags from an xml file. But how this is achieved is, in all blank lines /^$/, don't do this s/<[^>]*>//g;p;

!{s/<[^>]*>//g;p;} --> Not of {substitute contents in <> including <> with null}

Which looks like an equivalent of sed 's/<[^>]*>//g' filename

It appears to be an overkill. I could be wrong. May be someone more experienced in sed would know why it is the way it is.
This User Gave Thanks to balajesuri For This Post:
# 4  
Could you tell us which part of the code you don't understand ?

If you understand nothing, reading the following would be a good start :

[Appendix A] A.2 Syntax of sed Commands

[Chapter 3] 3.2 A Line-Up of Characters

Then tell us which part of the code you don't understand
This User Gave Thanks to ctsgnb For This Post:

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #770
Difficulty: Medium
IBM POWER4 (2001) had off-chip L3 caches of 32 MB per processor, shared among several processors.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Explain sed command

sed -e 's,*$,,' Can someone explain the options in this command? (2 Replies)
Discussion started by: scj2012
2 Replies

2. Shell Programming and Scripting

can you explain this sed code?

can anyone please explain this code? sed ':a;N;$!ba;s/]\n//g' file it replaces lines ending with "]" and concatenates with the next line so that line1] line2 becomes line1line2 i don't understand this part: :a;N;$!ba; I have noted that I can replace "a" with any letter: ... (1 Reply)
Discussion started by: locoroco
1 Replies

3. UNIX for Advanced & Expert Users

Please explain this sed one liner

Can anyone explain the below sed oneliner? sed -e ':a' -e '$q;N;11,$D;ba' It works same as tail command. I just want to know how it works. Thanks ---------- Post updated at 11:42 PM ---------- Previous update was at 11:37 PM ---------- Moderators, Can you please delete this thread?... (0 Replies)
Discussion started by: pandeesh
0 Replies

4. Shell Programming and Scripting

Please explain this SED expression

can anyone please explain this code? sed ':t /<VirtualHost/,/VirtualHost>/ { /VirtualHost>/!{ $!{ N; bt } }; /name/d; }' infile (4 Replies)
Discussion started by: jacky29
4 Replies

5. Shell Programming and Scripting

Explain following sed syntax please

Thanks to this forum I have managed to work out a solution to my problem and actually understand most of it, but one thing is confusing me and I am sure someone here can explain. I need to insert a piece of txt into a file. This txt is awk '{ sub(/$/,"\r"); print }' $JCL_WBB50103_EFTOUT >... (2 Replies)
Discussion started by: hukcjv
2 Replies

6. Shell Programming and Scripting

sed -e 's%/$%%' explain this command

mount -ps | tail -1 | awk '{print $1}' | sed -e 's%/$%%' can you please explain this command mainly sed -e 's%/$%%' this.... (5 Replies)
Discussion started by: rsivasan
5 Replies

7. Shell Programming and Scripting

h=`sed -n '57p' filename`

sed -n '57p' filename My file contains 57 lines ,the above command prints the 57 th line,but i want to assign the result of this to a variable, to compare with another line in a different file suggest me some idea if i directly use this to assign with variable like h=sed -n '57p' filename... (2 Replies)
Discussion started by: ragavendar
2 Replies

8. Shell Programming and Scripting

Explain SED code

Hi, Can anyone pls explain me the below SED code in detail. sed -e :a -e '$!N;s/\n//;ta' -e P -e D When this code is executed with a file(has 1lac records), it is taking very long time to process. So I wanted to modify this SED code with equivalant AWK code. Thanks, Sri (1 Reply)
Discussion started by: srilaxmi
1 Replies

9. Shell Programming and Scripting

please explain this sed shell script to remove C++ comments.

#! /bin/sed -nf # Remove C and C++ comments, by Brian Hiles ( # Sped up (and bugfixed to some extent) by Paolo Bonzini ( # Works its way through the line, copying to hold space the text up to the # first special character (/, ", '). The original... (1 Reply)
Discussion started by: Priyaranjan
1 Replies

10. Shell Programming and Scripting

sed / shell - how to use $filename

I've forgotten how to use a filename parameter using sed inside a shell script. What I want to do is replace a string inside a file with the name of the file being processed. I think this should work .. for filename do sed -e "s/xxx/$filename/" ... ... done Thanks! Ps: ... (5 Replies)
Discussion started by: eadie
5 Replies

Featured Tech Videos