On Sunday 10/06/2012 05:32, Stephane Chazelas wrote:
> 2012-06-09 04:51:05 +0000, foxidrive:
>> On Friday 08/06/2012 05:18, Stephane Chazelas wrote:
>>> 2012-06-08 04:12:47 +1000, foxidrive:
>>> [...]
>>>> sed -e "/^ *$/d" -e "/^$/d" "file.txt" > "newfile.txt"
>>>
>>> sed '$q;/[^ ]/!d'
>>
>> I'm not sure that it has the same function, Stephane. I tried
>> to adapt it to GnuSED but didn't have success.
>
> That should work with any shell. The quoting is Bourne-like
> shell syntax as found on all Unix-like systems.
>
> What you want is the string "$q;/[^ ]/!d" to be passed as the
> one and only argument to sed.
Thank you for your explanation.
This functions without an error in GnuSED but it removes the last line which is a blank line.
In the last command line below (type b.txt) I would like the blank line to remain in between each output of the sed command line.
c:\Files\Lists>type a.txt
Book: "The Taming of the Shrew"
Author: William Shakespeare
The main plot depicts the courtship of Petruchio, a gentleman of Verona,
and Katherina, the headstrong, obdurate shrew. Initially, Katherina is
an unwilling participant in the relationship, but Petruchio tempers her
with various psychological tormentsùthe "taming"ùuntil she becomes a
compliant and obedient bride.
c:\Files\Lists>sed "$q;/[^ ]/!d" a.txt
Book: "The Taming of the Shrew"
Author: William Shakespeare
The main plot depicts the courtship of Petruchio, a gentleman of Verona,
and Katherina, the headstrong, obdurate shrew. Initially, Katherina is
an unwilling participant in the relationship, but Petruchio tempers her
with various psychological torments-the "taming"-until she becomes a
compliant and obedient bride.
c:\Files\Lists>sed "$q;/[^ ]/!d" a.txt >>b.txt
c:\Files\Lists>sed "$q;/[^ ]/!d" a.txt >>b.txt
c:\Files\Lists>type b.txt
Book: "The Taming of the Shrew"
Author: William Shakespeare
The main plot depicts the courtship of Petruchio, a gentleman of Verona,
and Katherina, the headstrong, obdurate shrew. Initially, Katherina is
an unwilling participant in the relationship, but Petruchio tempers her
with various psychological tormentsùthe "taming"ùuntil she becomes a
compliant and obedient bride.
Book: "The Taming of the Shrew"
Author: William Shakespeare
The main plot depicts the courtship of Petruchio, a gentleman of Verona,
and Katherina, the headstrong, obdurate shrew. Initially, Katherina is
an unwilling participant in the relationship, but Petruchio tempers her
with various psychological tormentsùthe "taming"ùuntil she becomes a
compliant and obedient bride.
c:\Files\Lists>
It seems to be difficult.
> It says that, on the last line ($), sed should quit (q) (after
> having displayed the line).
>
> For any other line, unless it matches /[^ ]/ (contains any
> non-space), delete it (d). That is print all the lines that
> contain at least one non-space characters.
--
Mic