|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
|
Re: [PLUG] extended 'cut' functionality?
|
>> Is there anything that provides similar, but extended, functionality to
>> count from the _end_ of a string?
>> -Randall
to remove the last 3 characters I'd use:
sed 's/.\{3\}$//'
or even simpler
sed 's/...$//'
though the former scales better :)
it may not be as simple as cut-from-end 3 but imho it's easier to
remember how to use sed than the various flags of all the other unix
commands
> $ dirname /usr/share/doc/mysql-server-5.0/examples/my-small.cnf
> /usr/share/doc/mysql-server-5.0/examples
>
> This utility does not seem to read from standard input, so YMMV. You
> may be able to nest backticked statements, but that just seems so
> wrong...
>
> --
> Jim
xargs with the -n flag can do this kind of thing:
$ perldoc -l IO::Compress::Zip | xargs -n 1 dirname
/usr/lib/perl5/core_perl/IO/Compress
If you have problems with spaces in names you can add quotes using (again) sed
$ echo "/root/silly dir/file.txt" | xargs -n 1 dirname
/root
dir
$ echo "/root/silly dir/file.txt" | sed 's/.*/"&"/' | xargs -n 1 dirname
/root/silly dir
___________________________________________________________________________
Philadelphia Linux Users Group -- http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|