Sponsored Content
Full Discussion: sed one Liner option -e
Top Forums Shell Programming and Scripting sed one Liner option -e Post 302942276 by RudiC on Monday 27th of April 2015 05:31:41 AM
Old 04-27-2015
That one liner actually does what it is said to do. The -es are not needed (at least in my linux mawk). Try printing the pattern space with the l command to see how it proceeds. If it finds only zero or more <NL> (\n) chars in the pattern space which is one or more empty lines, it apends the next line. If that is empty as well, repeat. If it's the last line, quit. Any other line, print the ensemble:
Code:
sed 'l; :a /^\n*$/{$d;N;l;ba}' file
foo$
foo
$
\n$
\n\nbar$


bar
baz$
baz
$
\n$
\n\n$
\n\n\n$
\n\n\n\n$

This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Awk/Sed One liner for text replacement

Hi group, I want to replace the occurance of a particular text in a paragraph.I tried with Sed,but Sed only displays the result on the screen.How can i update the changes in the original file??? The solution should be a one liner using awk and sed. Thanks in advance. (5 Replies)
Discussion started by: bishnu.bhatta
5 Replies

2. Shell Programming and Scripting

Issue with a sed one liner variant - sed 's/ ; /|/g' $TMP1 > $TMP

Execution of the following segment is giving the error - Script extract:- OUT=$DATADIR/sol_rsult_orphn.bcp TMP1=${OUT}_tmp1 TMP=${OUT}_tmp ( isql -w 400 $dbConnect_OPR <<EOF select convert(char(10), s.lead_id) +'|' + s.pho_loc_type, ";", s.sol_rsult_cmnt, ";", +'|'+ s.del_ind... (3 Replies)
Discussion started by: kzmatam
3 Replies

3. Shell Programming and Scripting

Sed one-liner to print specific lines?

I need to print specific lines from a file, say 2-5, 8, 12-15, 17, 19, 21-27. How do I achieve this? (2 Replies)
Discussion started by: Ilja
2 Replies

4. Shell Programming and Scripting

Clarification needed for a SED one liner

I want to use SED to replace all new line characters of a file, I googled and found this one liner sed '{:q;N;s/\n//g;t q}' infile what do :q;N; and t q mean in this script? (6 Replies)
Discussion started by: kevintse
6 Replies

5. Shell Programming and Scripting

SED | Awk flat file one liner

sed awk one liner (2 Replies)
Discussion started by: jap2614
2 Replies

6. Shell Programming and Scripting

help with sed one liner

hey everyone, I want to remove some characters from a string that i have with sed. For example if my string is: a0=bus a1=car a2=truck I want my output to look like this: bus car truck So i want to delete the two characters before the = and including the =. This is what i came up with... (3 Replies)
Discussion started by: GmGeubt
3 Replies

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

8. UNIX for Advanced & Expert Users

sed one liner simialr to tail command

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 (1 Reply)
Discussion started by: pandeesh
1 Replies

9. UNIX for Dummies Questions & Answers

sed one-liner

I have a data base of part numbers: AAA Thing1 BBB Thing2 CCC Thing3 File one is a list of part numbers: AAA234 BBB678 CCC2345 Is there a sed one-line that would compare a data base with and replace the part numbers so that the output looks like this? AAA234 Thing1 BBB678 Thing2... (5 Replies)
Discussion started by: jimmyf
5 Replies

10. UNIX for Dummies Questions & Answers

awk or sed one liner

I have a data base of part numbers: AAA Thing1 BBB Thing2 CCC Thing3 File one is a list of part numbers: XXXX AAA234 XXXX BBB678 XXXX CCC2345 Is there a sed one-line that would compare a data base with and replace the part numbers so that the output looks like this? XXXX AAA234... (7 Replies)
Discussion started by: jimmyf
7 Replies
ensemble(n)							    [incr Tcl]							       ensemble(n)

__________________________________________________________________________________________________________________________________________________

NAME
ensemble - create or modify a composite command SYNOPSIS
itcl::ensemble ensName ?command arg arg...? or ensemble ensName { part partName args body ... ensemble partName { part subPartName args body part subPartName args body ... } } _________________________________________________________________ DESCRIPTION
The ensemble command is used to create or modify a composite command. See the section WHAT IS AN ENSEMBLE? below for a brief overview of ensembles. If the ensemble command finds an existing ensemble called ensName, it updates that ensemble. Otherwise, it creates an ensemble called ensName. If the ensName is a simple name like "foo", then an ensemble command named "foo" is added to the current namespace context. If a command named "foo" already exists in that context, then it is deleted. If the ensName contains namespace qualifiers like "a::b::foo", then the namespace path is resolved, and the ensemble command is added that namespace context. Parent namespaces like "a" and "b" are cre- ated automatically, as needed. If the ensName contains spaces like "a::b::foo bar baz", then additional words like "bar" and "baz" are treated as sub-ensembles. Sub- ensembles are merely parts within an ensemble; they do not have a Tcl command associated with them. An ensemble like "foo" can have a sub- ensemble called "foo bar", which in turn can have a sub-ensemble called "foo bar baz". In this case, the sub-ensemble "foo bar" must be created before the sub-ensemble "foo bar baz" that resides within it. If there are any arguments following ensName, then they are treated as commands, and they are executed to update the ensemble. The follow- ing commands are recognized in this context: part and ensemble. The part command defines a new part for the ensemble. Its syntax is identical to the usual proc command, but it defines a part within an ensemble, instead of a Tcl command. If a part called partName already exists within the ensemble, then the part command returns an error. The ensemble command can be nested inside another ensemble command to define a sub-ensemble. WHAT IS AN ENSEMBLE
? The usual "info" command is a composite command--the command name info must be followed by a sub-command like body or globals. We will refer to a command like info as an ensemble, and to sub-commands like body or globals as its parts. Ensembles can be nested. For example, the info command has an ensemble info namespace within it. This ensemble has parts like info names- pace all and info namespace children. With ensembles, composite commands can be created and extended in an automatic way. Any package can find an existing ensemble and add new parts to it. So extension writers can add their own parts, for example, to the info command. The ensemble facility manages all of the part names and keeps track of unique abbreviations. Normally, you can abbreviate info complete to info comp. But if an extension adds the part info complexity, the minimum abbreviation for info complete becomes info complet. The ensemble facility not only automates the construction of composite commands, but it automates the error handling as well. If you invoke an ensemble command without specifying a part name, you get an automatically generated error message that summarizes the usage information. For example, when the info command is invoked without any arguments, it produces the following error message: wrong # args: should be one of... info args procname info body procname info cmdcount info commands ?pattern? info complete command info context info default procname arg varname info exists varName info globals ?pattern? info level ?number? info library info locals ?pattern? info namespace option ?arg arg ...? info patchlevel info procs ?pattern? info protection ?-command? ?-variable? name info script info tclversion info vars ?pattern? info which ?-command? ?-variable? ?-namespace? name You can also customize the way an ensemble responds to errors. When an ensemble encounters an unspecified or ambiguous part name, it looks for a part called @error. If it exists, then it is used to handle the error. This part will receive all of the arguments on the command line starting with the offending part name. It can find another way of resolving the command, or generate its own error message. EXAMPLE
We could use an ensemble to clean up the syntax of the various "wait" commands in Tcl/Tk. Instead of using a series of strange commands like this: vwait x tkwait visibility .top tkwait window . we could use commands with a uniform syntax, like this: wait variable x wait visibility .top wait window . The Tcl package could define the following ensemble: itcl::ensemble wait part variable {name} { uplevel vwait $name } The Tk package could add some options to this ensemble, with a command like this: itcl::ensemble wait { part visibility {name} { tkwait visibility $name } part window {name} { tkwait window $name } } Other extensions could add their own parts to the wait command too. KEYWORDS
ensemble, part, info itcl 3.0 ensemble(n)
All times are GMT -4. The time now is 02:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy