Explain SED code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Explain SED code
# 1  
Old 11-25-2009
Explain SED code

Hi,

Can anyone pls explain me the below SED code in detail.

Code:
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

Last edited by zaxxon; 11-25-2009 at 10:41 AM.. Reason: code tags
# 2  
Old 11-25-2009
:a _______ sets the label "a"
$!N ______ as long as it is not the last line, take the next one and add it to be processed
s/\n// ____ substitute all newlines vs nothing ie. delete them
ta _______ as long as this all is true, go back to label "a" and repeat

Not sure on the following ones, someone can explain better maybe:
P _______ print the stuff that has been taken with N
D _______ deletes a part if it has been gathered with N

Maybe you show a part of your input file and add an example of the desired output you want. Use code tags when doing so, ty.

Last edited by zaxxon; 11-25-2009 at 10:41 AM.. Reason: typo
Login or Register to Ask a Question

Previous Thread | Next Thread

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. UNIX for Dummies Questions & Answers

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) ... (3 Replies)
Discussion started by: maximus73
3 Replies

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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 (brian_hiles@rocketmail.com) # Sped up (and bugfixed to some extent) by Paolo Bonzini (bonzini@gnu.org) # 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

9. UNIX for Advanced & Expert Users

explain the code

Hi , Can anyone explains what does the below highlighted statements means: # Set environment variables . ${0%/*}/wrkenv.sh jobName_sh=${0##*/} jobName=${jobName_sh%.*} Thanks, Sri (1 Reply)
Discussion started by: srilaxmi
1 Replies

10. UNIX for Dummies Questions & Answers

could someone explain this code

hey peeps could someone explain what this part of the code means: 'if echo $* | grep -q' $i '|| thanks tHe_nEw_GuY (2 Replies)
Discussion started by: the_new_guy
2 Replies
Login or Register to Ask a Question