Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using multiple delimiters in a cut command

115 views
Skip to first unread message

Mark Hobley

unread,
Aug 31, 2008, 5:52:41 PM8/31/08
to
I would like to use a selection of characters for a field delimiter in
the cut utility. Is this possible?

To cut out hash marked comments, I can use:

cut -f 1 -d '#' foobar.txt

Supposing I want to also cut semicolon marked comments?

cut -f 1 -d '[#;]' foobar.txt # This does not work
cut -f 1 -d '#' -d ';' foobar.txt # Neither does this
cut -f 1 -d '#|;' foobar.txt # Neither does this

I know that I could use a cut for each character:

cut -f 1 -d '#' foobar.txt | cut -f 1 -d ';' # This kludge works

Mark.

--
Mark Hobley,
393 Quinton Road West,
Quinton, BIRMINGHAM.
B32 1QE.

Kenny McCormack

unread,
Aug 31, 2008, 8:14:02 PM8/31/08
to
In article <9egro5-...@neptune.markhobley.yi.org>,

Mark Hobley <markh...@hotpop.donottypethisbit.com> wrote:
>I would like to use a selection of characters for a field delimiter in
>the cut utility. Is this possible?
>
>To cut out hash marked comments, I can use:
>
>cut -f 1 -d '#' foobar.txt
>
>Supposing I want to also cut semicolon marked comments?
>
>cut -f 1 -d '[#;]' foobar.txt # This does not work
>cut -f 1 -d '#' -d ';' foobar.txt # Neither does this
>cut -f 1 -d '#|;' foobar.txt # Neither does this
>
>I know that I could use a cut for each character:
>
>cut -f 1 -d '#' foobar.txt | cut -f 1 -d ';' # This kludge works

Wouldn't it be better to use a more powerful tool, such as AWK?

And, BTW, this is more of a comp.unix.shell question than a
comp.unix.programmer one.

0 new messages