[Techtalk] real life kewl text-processing and regexps samples
wanted
Conor Daly
conor.daly at oceanfree.net
Sun Jan 25 20:38:12 EST 2004
On Fri, Jan 09, 2004 at 08:19:21PM -0500 or so it is rumoured hereabouts,
Brenda Bell thought:
>
> I don't have any examples, but the cut command is one of my
> favorites:
>
> cat test.txt | cut -d= -f1
>
> Will print the first "field" of a file where fields are delimited
> by = and "records" are delimited by new lines.
I know I'm replying 2 weeks later but still...
One thing that bothers me with cut is when I do
ls -l | cut -f6-8 -d' '
to extract the date from a file list and cut goes and counts spaces and
gives me my UID and 2 spaces instead of the date fields. I know cut is
doing what it's told but I want it to treat any whitespace as a single
space. Anyone know how I should do that? Currently I'll do:
ls -l | sed -e 's/ \{1,\}/ /g' | cut -f6-8 -d' '
where:
sed -e 's/ \{1,\}/ /g'
^^^^^^
means "replace a space followed by 1 or more spaces with just one space"
Conor
--
Conor Daly <conor.daly at oceanfree.net>
Domestic Sysadmin :-)
---------------------
Faenor.cod.ie
7:35pm up 94 days, 12:44, 0 users, load average: 0.00, 0.00, 0.00
Hobbiton.cod.ie
7:30pm up 94 days, 12:33, 1 user, load average: 0.00, 0.00, 0.00
More information about the Techtalk
mailing list