Almir Karic | 1 Jul 17:19 2008
Picon

Re: How to delete ANY characters in a string except [[:upper:]] ?

On Sun, Jun 29, 2008 at 1:06 AM, Michelle Konzack
<linux4michelle <at> tamay-dogan.net> wrote:
> Hello Oleg,
>
> Am 2008-06-27 19:01:57, schrieb Oleg Verych:
>> >> I like to delete ANY characters in a string except [[:upper:]].
>> >
>> > Just use [^[:upper:]]
>> >
>> > sed 's/[^[:upper:]]//g'
>>
>> or (much) faster: `sed 's/[^[:upper:]]\{1,\}//g'`
>
> I do not understand this. Why is \{1,\} faster ?

it should be faster if you've got several consecutivenon upper
letters, tim's example will replace them one by one, oleg's example
should replace all consecutive non upper letters in one replacement.

--
For far too long, power has been concentrated in the hands of "root"
and his "wheel" oligarchy. We have instituted a dictatorship of the
users. All system administration functions will be handled by the
People's Committee for Democratically Organizing the System (PC-DOS).

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Need traffic?

Drive customers

With search ads

on Yahoo!

All-Bran

10 Day Challenge

Join the club and

feel the benefits.

.

__,_._,___
persson | 1 Jul 17:36 2008

Re: How to delete ANY characters in a string except [[:upper:]] ?

On Sunday 29 June 2008, 01:06, Michelle Konzack wrote:
> Hello Oleg,
>
> Am 2008-06-27 19:01:57, schrieb Oleg Verych:
> > >> I like to delete ANY characters in a string except [[:upper:]].
> > >
> > > Just use [^[:upper:]]
> > >
> > > sed 's/[^[:upper:]]//g'
> >
> > or (much) faster: `sed 's/[^[:upper:]]\{1,\}//g'`
>
> I do not understand this. Why is \{1,\} faster ?

I suppose that's because the quantifier lets sed "eat" more characters at
a time if they are available, rather than having to examine every single
character.

$ time sed 's/[^[:upper:]]//g' file2 > /dev/null

real 0m1.869s
user 0m1.851s
sys 0m0.019s

$ time sed 's/[^[:upper:]]\{1,\}//g' file2 > /dev/null

real 0m0.787s
user 0m0.780s
sys 0m0.008s

"file2" is a ~1.7MB file.

__._,_.___
MARKETPLACE
Attention, Yahoo! Groups users! Sign up now for a one-month free trial from Blockbuster. Limited time offer.
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

New business?

Get new customers.

List your web site

in Yahoo! Search.

Sell Online

Start selling with

our award-winning

e-commerce tools.

.

__,_._,___
Jason Unrein | 1 Jul 20:42 2008
Picon

[:digit:] not working the same as [0-9]

I'm trying to figure out why this command doesn't work as expected

cat /etc/redhat-release | sed
's/\([[:alpha:]|[:blank:]]*\)\([:digit:]*\)\(.*\)/0 = \0\n1 = \1\n2 =
\2\n3 = \3/'
0 = Red Hat Enterprise Linux AS release 4 (Nahant Update 6)
1 = Red Hat Enterprise Linux AS release
2 =
3 = 4 (Nahant Update 6)

If I run it, with :digit: replaced with 0-9, it works as expected.

cat /etc/redhat-release | sed
's/\([[:alpha:]|[:blank:]]*\)\([0-9]*\)\(.*\)/0 = \0\n1 = \1\n2 =
\2\n3 = \3/'
0 = Red Hat Enterprise Linux AS release 4 (Nahant Update 6)
1 = Red Hat Enterprise Linux AS release
2 = 4
3 = (Nahant Update 6)

What's the difference?

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Drive Traffic

Sponsored Search

can help increase

your site traffic.

Need traffic?

Drive customers

With search ads

on Yahoo!

.

__,_._,___
Almir Karic | 2 Jul 11:05 2008
Picon

Re: [:digit:] not working the same as [0-9]

use [[:digit:]] instead.

On Tue, Jul 1, 2008 at 8:42 PM, Jason Unrein <diabelek <at> yahoo.com> wrote:
> I'm trying to figure out why this command doesn't work as expected
>
> cat /etc/redhat-release | sed
> 's/\([[:alpha:]|[:blank:]]*\)\([:digit:]*\)\(.*\)/0 = \0\n1 = \1\n2 =
> \2\n3 = \3/'
> 0 = Red Hat Enterprise Linux AS release 4 (Nahant Update 6)
> 1 = Red Hat Enterprise Linux AS release
> 2 =
> 3 = 4 (Nahant Update 6)
>
> If I run it, with :digit: replaced with 0-9, it works as expected.
>
> cat /etc/redhat-release | sed
> 's/\([[:alpha:]|[:blank:]]*\)\([0-9]*\)\(.*\)/0 = \0\n1 = \1\n2 =
> \2\n3 = \3/'
> 0 = Red Hat Enterprise Linux AS release 4 (Nahant Update 6)
> 1 = Red Hat Enterprise Linux AS release
> 2 = 4
> 3 = (Nahant Update 6)
>
>
> What's the difference?
>
>
> ------------------------------------
>
> --
> Yahoo! Groups Links
>
>
>
>

--
For far too long, power has been concentrated in the hands of "root"
and his "wheel" oligarchy. We have instituted a dictatorship of the
users. All system administration functions will be handled by the
People's Committee for Democratically Organizing the System (PC-DOS).

__._,_.___
Recent Activity
Visit Your Group
Sitebuilder

Build a web site

quickly & easily

with Sitebuilder.

Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Need traffic?

Drive customers

With search ads

on Yahoo!

.

__,_._,___
Eric Pement | 3 Jul 05:55 2008

Re: [:digit:] not working the same as [0-9]

Replying to Jason:

> I'm trying to figure out why this command doesn't work as expected
>
> cat /etc/redhat-release | sed
> 's/\([[:alpha:]|[:blank:]]*\)\([:digit:]*\)\(.*\)/0 = \0\n1 = \1\n2 =
> \2\n3 = \3/'

[:digit:] is not a valid representation of a character. [:digit:] is a
named character class, and it is only valid INSIDE of a character set,
which means one more set of square brackets. Thus, [a-fA-F[:digit:]] or
[[:digit:]] or something like that.

And about this construction:

[[:alpha:]|[:blank:]]

That does NOT represent any single character which is either an
alphabetic letter OR a whitespace character. There is no vertical bar
representing alternation in a character set. The vertical bar will be
treated literally inside a character set. (Maybe you knew this
already.)

HTH.

--
Eric Pement - pemente <at> northpark.edu

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Yahoo! Groups

Join people over 40

who are finding ways

to stay in shape.

Family Photos

Learn how to best

capture your

family moments.

.

__,_._,___
user_nine | 6 Jul 12:37 2008
Picon

Show a special column

ENV: WINXPSP3
SED 4.7 from UnxUtils

Using Gnu's unzip.exe with list switch (unzip -l archive) I get
something like this in console:

Archive: batchcompiler.zip
Length EAs ACLs Date Time Name
-------- --- ---- ---- ---- ----
20512 0 0 22.03.03 01:00 Batch Compiler.exe
154 0 0 22.03.03 01:13 Example.bat
117 0 0 22.03.03 01:15 Example 2.bat
1499 0 0 22.03.03 01:11 Help.txt
10784 0 0 22.03.03 00:47 Rn.dll
15511 0 0 31.05.08 06:45 Homepage/BatchCompiler.mht
213 0 0 31.05.08 06:45 Homepage/BatchCompiler.url
318 0 0 18.06.08 11:29 BatchCompiler.ico
-------- ----- ----- -------
49108 0 0 8 files

...the spaces between columns are really spaces - no tabs.

I wanna pipe it into sed but only showing the fourth column which
shows the file/folder list.

unzip -l archive|sed "s/.*[ ]\+//"
...will eat the first word from "Batch Compiler.exe" and "Example 2.bat"

Best would be having an output like this:

Batch Compiler.exe
Example.bat
Example 2.bat
Help.txt
Rn.dll
Homepage/BatchCompiler.mht
Homepage/BatchCompiler.url
BatchCompiler.ico

..without header and footer

Could someone guide me how to do this and/or provide a research link
for this task?

Thanks in advance for any reply
Zharif

__._,_.___
MARKETPLACE
Special offer for Yahoo! Groups from Blockbuster! Get a free 1-month trial with no late fees or due dates.
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Biz Resources

Y! Small Business

Articles, tools,

forms, and more.

Need traffic?

Drive customers

With search ads

on Yahoo!

.

__,_._,___
Almir Karic | 6 Jul 14:23 2008
Picon

Re: Show a special column

On Sun, Jul 6, 2008 at 12:37 PM, user_nine <zharif <at> arcor.de> wrote:
> ENV: WINXPSP3
> SED 4.7 from UnxUtils
>
> Using Gnu's unzip.exe with list switch (unzip -l archive) I get
> something like this in console:
>
> Archive: batchcompiler.zip
> Length EAs ACLs Date Time Name
> -------- --- ---- ---- ---- ----
> 20512 0 0 22.03.03 01:00 Batch Compiler.exe
> 154 0 0 22.03.03 01:13 Example.bat
> 117 0 0 22.03.03 01:15 Example 2.bat
> 1499 0 0 22.03.03 01:11 Help.txt
> 10784 0 0 22.03.03 00:47 Rn.dll
> 15511 0 0 31.05.08 06:45 Homepage/BatchCompiler.mht
> 213 0 0 31.05.08 06:45 Homepage/BatchCompiler.url
> 318 0 0 18.06.08 11:29 BatchCompiler.ico
> -------- ----- ----- -------
> 49108 0 0 8 files
>
> ...the spaces between columns are really spaces - no tabs.
>
> I wanna pipe it into sed but only showing the fourth column which
> shows the file/folder list.
>
> unzip -l archive|sed "s/.*[ ]\+//"
> ...will eat the first word from "Batch Compiler.exe" and "Example 2.bat"
>
> Best would be having an output like this:
>
> Batch Compiler.exe
> Example.bat
> Example 2.bat
> Help.txt
> Rn.dll
> Homepage/BatchCompiler.mht
> Homepage/BatchCompiler.url
> BatchCompiler.ico
>
> ..without header and footer
>
> Could someone guide me how to do this and/or provide a research link
> for this task?

awk '{ print $6 }'

does the trick on linux (i think you have to use double quotes on
windows). if you insist on using sed:

sed 's/\([[:space:]]*[^[:space:]]*\)\{5\}[[:space:]]*//'

will print you sixth column.

sed 's/^[^a-zA-Z]*//'

will remove everything before the first letter. all of examples work
on the provided input.

--
For far too long, power has been concentrated in the hands of "root"
and his "wheel" oligarchy. We have instituted a dictatorship of the
users. All system administration functions will be handled by the
People's Committee for Democratically Organizing the System (PC-DOS).

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Need traffic?

Drive customers

With search ads

on Yahoo!

Sell Online

Start selling with

our award-winning

e-commerce tools.

.

__,_._,___
user_nine | 6 Jul 14:56 2008
Picon

Re: Show a special column

--- In sed-users <at> yahoogroups.com, "Almir Karic" <redduck666 <at> ...> wrote:
>
> awk '{ print $6 }'
>
> does the trick on linux (i think you have to use double quotes on
> windows). if you insist on using sed:
>
> sed 's/\([[:space:]]*[^[:space:]]*\)\{5\}[[:space:]]*//'
>
> will print you sixth column.
>
> sed 's/^[^a-zA-Z]*//'
>
> will remove everything before the first letter. all of examples work
> on the provided input.
>
> --

Thanks Almir,
It's impressive to see how short the code lines are for this task by
using awk.
Hmm, I think I should try to learn the awk syntax under windows using
the GnuWin32 version.
It's a real mess to do this by using windows batching language (here:
FOR loops by using tokens= delims=) - and so sloooow.

Thanks for your provided sed solution.
It's quite simple and should work (didn't tried it yet).
...I should have a look OVER the wall some more times - thank you.

__._,_.___
MARKETPLACE
You rock! Blockbuster wants to give you a complimentary trial of - Blockbuster Tota l Access.
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Biz Resources

Y! Small Business

Articles, tools,

forms, and more.

Need traffic?

Drive customers

With search ads

on Yahoo!

.

__,_._,___
Tim Chase | 6 Jul 15:06 2008

Re: Show a special column

>> 213 0 0 31.05.08 06:45 Homepage/BatchCompiler.url
>
> sed 's/\([[:space:]]*[^[:space:]]*\)\{5\}[[:space:]]*//'
>
> will print you sixth column.
[snip]
> sed 's/^[^a-zA-Z]*//'
>
> will remove everything before the first letter. all of examples work
> on the provided input.

If you have foreknowledge that your filenames always begin with a
letter, the second solution is easier to type & read. However,
if you can have filenames like "123test.txt" then you will end up
with just "test.txt" as your filename. The first solution solves
this but is more complex to type.

-tim

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

New web site?

Drive traffic now.

Get your business

on Yahoo! search.

Sitebuilder

Build a web site

quickly & easily

with Sitebuilder.

.

__,_._,___
persson | 6 Jul 15:24 2008

Re: Show a special column

On Sunday 6 July 2008, 14:56, user_nine wrote:

> --- In sed-users <at> yahoogroups.com, "Almir Karic" <redduck666 <at> ...> wrote:
> > awk '{ print $6 }'
> >
> > does the trick on linux (i think you have to use double quotes on
> > windows). if you insist on using sed:
> >
> > sed 's/\([[:space:]]*[^[:space:]]*\)\{5\}[[:space:]]*//'
> >
> > will print you sixth column.
> >
> > sed 's/^[^a-zA-Z]*//'
> >
> > will remove everything before the first letter. all of examples work
> > on the provided input.
> >
> > --
>
> Thanks Almir,
> It's impressive to see how short the code lines are for this task by
> using awk.

Note that there may be problems with awk if you have spaces in the
filenames (as it seems).

Another sed solution that should work, assuming the output is exactly as
you show, is

sed -n '1,2b;/^ ----/b;$b;s/^.\{42\}//p'

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Find Balance

on Yahoo! Groups

manage nutrition,

activity & well-being.

Y! Groups blog

The place to go

to stay informed

on Groups news!

.

__,_._,___

Gmane