SPUG:Best One-Liners and Scripts for UNIX
Brian Hatch
spug at ifokr.org
Wed Apr 16 22:44:33 CDT 2003
> Seems like most people stayed home to work on their taxes last
> night, judging from the turnout at our April SPUG meeting 8-{
I hope to make the next one. I can only attend one evening
geek meeting between SAGE and SPUG or my wife would kill me.
Perhaps if you changed it to be later in the month... ;-)
> * 5 Perl One-liners All Unix/Linux Users Should Know
Well, I tend to functionize my perl one liners, but here are
some of my favorites:
function forkoff {
perl -we "\$SIG{HUP}='IGNORE'; fork || fork && exec @ARGV" "$@";
}
A better version of 'nohup' because the process gets
inherited by init and totally dissociates, meaning you
can log off and ssh won't hang on you.
function sp {
delim=" "
if [ "$1" = '-F' ] ; then
shift;
delim=$1;
shift;
fi
fields=$1;
shift;
$PERL5 "-F$delim" -ape 'chomp @F; $_=join(" ",grep /./, @F['$fields'])."\n"' $@
}
Yeah, that's much longer than one line, but it could be reduced
to this if you don't want to support alternate delimeters:
function sp {
$PERL5 -ape 'chomp @F; $_=join(" ",grep /./, @F['$fields'])."\n"' $@
}
It's a quick dirty way to say 'show me fields X,Y,Z from the source file'
using perl's array slices, ala
sp -F : 0,4 /etc/passwd # show username and gecos
sp 1..3 /some/file # show fields 2-4 from /some/file
/some/process | sp 5,6,2,4 # show fields from /some/process output
function showfunc {
functions | perl -e 'do { $_=<>; exit if eof } until ( /^function '$1'/ ); print; print while $_=<> and not /^function/'
}
Good function to show you the body of a function using perl. (For those
shells that don't support 'typeset -f functionname')
Of course any '-i.bak' style one liner is invaluable.
> * 3 Perl Scripts UNIX/Linux Users Shouldn't Live Without
#!/usr/bin/perl
@list=<STDIN>;
for (@list) {
s/^> //;
print "\n" unless /\S/;
write;
}
format STDOUT =
> ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
$_
.
To re-format (badly, but sufficiently) email text that isn't
wrapped well.
--
Brian Hatch Plagiarism
Systems and saves
Security Engineer time.
http://www.ifokr.org/bri/
Every message PGP signed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/spug-list/attachments/20030416/30407c0e/attachment.bin
More information about the spug-list
mailing list