Strip XML comments with sed
Posted Sun, 14 Jan 2007
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.
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.
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" leI 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.
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.
find ./ -type f | xapply -f 'grep "SOMESTRING" "%1" | sed -e "s!^!%1: !"' -
perl -lne 'print $a+=$_'
perl -e '$foo = "hello there"; $foo =~ /(?{chop}){4}/; print "$foo\n"'
Nuff said.
You may have to look up what (?{...}) does in perldoc perlre
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.
dd if=/dev/urandom bs=1 count=30 2> /dev/null | \
perl -e 'read(STDIN,$foo,5); print unpack("J",$foo) % 6 . "\n";'
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) };
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***