photo
Jordan Sissel
geek. sysadmin. blogger.

Sun, 14 Jan 2007

Strip XML comments with sed

sed -ne '/<!--/ { :c; /-->/! { N; b c; }; /-->/s/<!--.*-->//g }; /^  *$/!p;'
You might consider stripping blanklines and/or filtering through xmllint --format to make the xml pretty printed.

Comments: 2 (view comments)
Tags: , ,
Permalink: /geekery/strip-comments-from-xml-with-sed
posted at: 19:48

Thu, 23 Mar 2006

Site move soon, perhaps.

I'll be moving this site to my new domain as soon as I get things setup there. I won't bother disclosing the name at this point, seeing as how there's nothing there.

As a hint, however, I will say I came up with the name using this perl one-liner:

perl -Mre=eval -ne 'print if m/^s(.)(??{"[^$1]+$1"}){2}$/' words
(are your eyes bleeding, yet?)

That regex will find all valid sed substitution expressions in the file 'words' (freebsd's dictionary file). So, anything printed by that perl code will be valid as a sed command. ie: "streetlet" is valid as

% echo "ree" | sed -e "streetlet"
le
I learned a new word in the process of running this script. syzygy

Nothing quite like using perl to choose a domain name for you. Yeah, I'm a dork.

Comments: 1 (view comments)
Tags: ,
Permalink: /site/sitemove
posted at: 15:26

Wed, 22 Feb 2006

precedence sorting with perl's sort()

This isn't terribly complicated, but it may be useful to you. Mostly I'm putting it here for my own future reference.
sort { $users{$b} <=> $users{$a} || $a cmp $b } keys(%users)
This will sort first numerically by the values stored in %users and then by the keys of %users. This means that the return value of sort is the keys sorted by data values first, and then alphabetically when both data values are equal.

Comments: 0 (view comments)
Tags: ,
Permalink: /geekery/219
posted at: 17:40

Fri, 15 Oct 2004

grep -R

Boredom + lacking grep with -R...

find ./ -type f | xapply -f 'grep "SOMESTRING" "%1" | sed -e "s!^!%1: !"' -

Comments: 0 (view comments)
Tags:
Permalink: /oneliners/129
posted at: 14:37

Fri, 01 Oct 2004

perl makes addition fun!

I like calculators...

perl -lne 'print $a+=$_'

Comments: 0 (view comments)
Tags: ,
Permalink: /geekery/126
posted at: 19:39

Thu, 05 Aug 2004

happy perl obfuscation #425234569807


perl -e '$foo = "hello there"; $foo =~ /(?{chop}){4}/; print "$foo\n"'

Nuff said.

You may have to look up what (?{...}) does in perldoc perlre

Comments: 0 (view comments)
Tags: ,
Permalink: /geekery/123
posted at: 00:29

Sun, 11 Jul 2004

boredom + apache

Here's a silly oneliner that'll attempt to calculate per-file usage from an apache log.

awk '{print $7}' - | perl -e 'while (<>) { chomp; s!^/([^/]+)!/.html_pages!; 
$u = $1; next if ($u !~ s/^~//); @a = getpwuid(getpwnam($u)); $_ = $a[7] . $_;
$f{$_} += (stat($_))[7] }; map { print $f{$_} . " $_\n" if ($f{$_}) } keys(%f)'

Reads the log data from stdin. Output is unsorted. I'd make it smaller but I'm lazy and tired.

Comments: 0 (view comments)
Tags: ,
Permalink: /oneliners/122
posted at: 08:24

Wed, 23 Jun 2004

Yet another random number generator

I was bored...

dd if=/dev/urandom bs=1 count=30 2> /dev/null | \
perl -e 'read(STDIN,$foo,5); print unpack("J",$foo) % 6 . "\n";'

Comments: 0 (view comments)
Tags: ,
Permalink: /oneliners/120
posted at: 23:56

Sun, 20 Jun 2004

Removing duplicates from arrays in Perl

After needing to do this in a project of mine, I went googling and found, as expected, a wide variety of solutions. Solutions ranged from using map, foreach, grep, etc.. All using things like a temporary hash to count instances and ensure uniqueness - but I remembered that hashes have unique keys and that hashes are often treated the same way as arrays in perl, so my solution is as follows:

my %foo;  #Temp var
my @a = qw (hello there hello how are you today there what now hello hello hello);

%foo = @a;
@a = keys(%foo);

I also have a one-liner version:

# Assumedly, @a is already defined and has stuff in it, perhaps...

@a = do { my %foo = @a; keys(%foo) };

Comments: 3 (view comments)
Tags: ,
Permalink: /geekery/118
posted at: 19:19

Mon, 29 Sep 2003

<3 xapply.

xapply 'ping -t 1 -c 1 %1 > /dev/null 2>&1; A=$?; echo -n "%1 - "; [ $A -eq 0 ] && echo "ONLINE" || echo "***DOWN***"' `cat hostlist`

Outputs:

project1 - ONLINE
mokey - ***DOWN***
boober - ONLINE
wimbley - ONLINE
doozer - ONLINE
felix - ONLINE
red - ***DOWN***
sprocket - ONLINE
henchy - ONLINE
falcon - ONLINE
talon - ONLINE
junior - ONLINE
doc - ONLINE
eagle - ***DOWN***

Comments: 0 (view comments)
Tags: ,
Permalink: /oneliners/67
posted at: 13:22

Search this site

Navigation

Page 1 of 2  [next]

Metadata

Home About Resume My Code (SVN Web)

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials

Tag Cloud

Calendar

< January 2007 >
SuMoTuWeThFrSa
  1 2 3 4 5 6
7 8 910111213
14151617181920
21222324252627
28293031   

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati