
Terminal - Commands tagged perl - 178 results
git status | perl -F'\s' -nale 'BEGIN { $a = 0 }; $a = 1 if $_ =~ /changed but not updated/i; print $F[-1] if ( $a && -f $F[-1] )'
This is sample output - yours may be different.
Parse the output of git status.
Once the line '# Changed but not updated:' has passed print every last part of the line if it exists on disk.
diff <(perl -wpl -e '$_ =~ s/^\s+|\s+$//g ;' file1) <(perl -wpl -e '$_ =~ s/^\s+|\s+$//g ;' file2)
This is sample output - yours may be different.
gjempty$ diff <(perl -wpl -e '$_ =~ s/^\s+|\s+$//g ;' file1) <(perl -wpl -e '$_ =~ s/^\s+|\s+$//g ;' file2)
247a248,250
> for ($i = 0; $i < 7; $i++) {
> if (!isset($tabData[$i])) $tabData[$i] = '';
> }
gjempty$ diff -b file1 file2
247a248,250
> for ($i = 0; $i < 7; $i++) {
> if (!isset($tabData[$i])) $tabData[$i] = '';
> }
**NOTE** Tekhne's alternative is much more succinct and its output conforms to the files actual contents rather than with white space removed
My command on the other hand uses bash process substitution (and "Minimal" Perl), instead of files, to first remove leading and trailing white space from lines, before diff'ing the streams. Very useful when differences in indentation, such as in programming source code files, may be irrelevant
find . -iname '*.jpg' -type f -print0 |perl -0 -ne '$a+=-s $_;END{print "$a\n"}'
This is sample output - yours may be different.
This deals nicely with filenames containing special characters and can deal with more files than can fit on a commandline. It also avoids spawning du.
perl -le 'chomp($w=`which $ARGV[0]`);$_=`file $w`;while(/link\b/){chomp($_=(split/`/,$_)[1]);chop$_;$w.=" -> $_";$_=`file $_`;}print "\n$w";' COMMAND_NAME
This is sample output - yours may be different.
$ perl -le 'chomp($w=`which $ARGV[0]`);$_=`file $w`;while(/link\b/){chomp($_=(split/`/,$_)[1]);chop$_;$w.=" -> $_";$_=`file $_`;}print "\n$w";' vi
/usr/bin/vi -> /etc/alternatives/vi -> /usr/bin/vim.gtk
This will show you any links that a command follows (unlike 'file -L'), as well as the ultimate binary or script.
Put the name of the command at the very end; this will be passed to perl as the first argument.
For obvious reasons, this doesn't work with aliases or functions.
This is sample output - yours may be different.
This is sample output - yours may be different.
Just use "od" and it can also dump in decimal or octal.
(use -t x1 and not just -x or it confuses the byte order)
There is a load of other formatting options, I'm not sure if you can turn off the address at the start of the line.
echo -n 'text' | perl -pe 's/(.)/sprintf("\\x%x", ord($1))/eg'
This is sample output - yours may be different.
Here's a version that uses perl. If you'd like a trailing newline:
perl -pe 's/(.)/sprintf("\\x%x", ord($1))/eg; END {print "\n"}'
perl -e 'print "\x41\x72\x74\x20\x6f\x66\x20\x68\x61\x63\x6b\x69\x6e\x67\x2e\x2e\x2e\n" x 100'
This is sample output - yours may be different.
[email protected]:~/shellcode$ perl -e 'print "\x41\x72\x74\x20\x6f\x66\x20\x68\x61\x63\x6b\x69\x6e\x67\x2e\x2e\x2e\n" x 100'
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
Art of hacking...
[email protected]:~/shellcode$
cat file_with_tabs.txt | perl -pe 's/\t/ /g'
This is sample output - yours may be different.
Replaces tabs in output with spaces. Uses perl since sed seems to work differently across platforms.
perl -MNet::Twitter -e '$nt = Net::Twitter->new(traits => [qw/API::REST/], username => "YOUR USERNAME", password => "YOUR PASSWORD"); $ud = $nt->update("YOUR TWEET");'
This is sample output - yours may be different.
Requires Net::Twitter. Just replace the double quoted strings with the appropriate info.
git log -p -z | perl -ln0e 'print if /[+-].*searchedstring/'
This is sample output - yours may be different.
aptitude purge linux-image | grep ^i | grep -v $(uname -r)
This is sample output - yours may be different.
perl -e 'chomp($k=`uname -r`); for (</boot/vm*>) {s/^.*vmlinuz-($k)?//; $l.="linux-image-$_ ";} system "aptitude remove $l";'
This is sample output - yours may be different.
for code in $(find . -type f -name '*.p[ml]'); do perl -c "$code"; done
This is sample output - yours may be different.
./foo.pl syntax OK
./bar/Baz.pm syntax OK
...
Finds all *.p[ml]-files and runs a perl -c on them, checking whether Perl thinks they are syntactically correct
perl -e 'foreach (@ARGV) {@T=stat($_); print localtime($T[8])." - ".$_."\n"}'
This is sample output - yours may be different.
perl -e '@F = `ls -1`;while (<@F>){@T = stat($_);print "$_ = " . localtime($T[8]) . "\n";}'
This is sample output - yours may be different.
Test_DR.sh = Mon Jul 6 09:22:35 2009
Test_DR.sh-20080806-hck = Sun Aug 17 13:46:34 2008
Test_DR.sh~ = Sun Aug 17 13:49:59 2008
utk_cod-savesets = Wed Mar 14 11:20:46 2007
utkdc8 = Fri Nov 3 17:18:21 2006
Vics-data = Thu Jan 21 14:30:29 2010
Solaris 'ls' command does not have a nice '--full-time' arg to make the time show after a year has passed. So I spit this out quick. It hates spaces in file names.
perl -MDigest::SHA -e 'print substr( Digest::SHA::sha256_base64( time() ), 0, $ARGV[0] ) . "\n"' <length>
This is sample output - yours may be different.
Of course you will have to install Digest::SHA and perl before this will work :)
Maximum length is 43 for SHA256. If you need more, use SHA512 or the hexadecimal form: sha256_hex()
echo $hex | perl -pe 's/(..)/chr(hex($1))/ge'
This is sample output - yours may be different.
perl -i -pe 's/\r/\n/g' file
This is sample output - yours may be different.
This is sample output - yours may be different.
Thu Jun 25 10:48:08 2009: "Module" IO::Dir::Recursive
? "installed into: /usr/lib/perl5/site_perl/5.8.8"
? "LINKTYPE: dynamic"
? "VERSION: 0.03"
? "EXE_FILES: "
This command will give you the detailed information about the installed perl modules i.e. installed path, Link type, version, files etc.
curl -s http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=${@:-<YOURZIPORLOCATION>}|xmlstarlet sel -E utf-8 -t -m //forecast/txt_forecast/forecastday -v fcttext -n
This is sample output - yours may be different.
you can use xmlstarlet to parse output instead of perl
perl -MStatistics::Descriptive -alne 'my $stat = Statistics::Descriptive::Full->new; $stat->add_data(@F[1..4]); print $stat->variance' filename
This is sample output - yours may be different.
$ cat test
A 25 26 24 28
B 10 20 30 40
C 10 20 10 20
$ perl -MStatistics::Descriptive -alne 'my $stat = Statistics::Descriptive::Full->new; $stat->add_data(@F[1..4]); print $stat->variance' test
2.91666666666667
166.666666666667
33.3333333333333
In this example, file contains five columns where first column is text. Variance is calculated for columns 2 - 5 by using perl module Statistics::Descriptive. There are many more statistical functions available in the module.
perl -pi -e 's/\r\n?/\n/g'
This is sample output - yours may be different.
This method will also convert mac line endings.
perl -ne 'BEGIN{undef $/}; print "$ARGV\t$.\t$1\n" if m/(first line.*\n.*second line)/mg'
This is sample output - yours may be different.
Using perl you can search for patterns spanning several lines, a thing that grep can't do. Append the list of files to above command or pipe a file through it, just as with regular grep. If you add the 's' modifier to the regex, the dot '.' also matches line endings, useful if you don't known how many lines you need are between parts of your pattern. Change '*' to '*?' to make it greedy, that is match only as few characters as possible.
See also http://www.commandlinefu.com/commands/view/1764/display-a-block-of-text-with-awk to do a similar thing with awk.
Edit: The undef has to be put in a begin-block, or a match in the first line would not be found.
echo "$url" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"'
This is sample output - yours may be different.
$ echo "this & that" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"'
this%20%26%20that
$ echo "this & that" | python -c 'import sys,urllib;print urllib.quote(sys.stdin.read().strip())'
this%20%26%20that
Converts reserved characters in a URI to their percent encoded counterparts.
Alternate python version:
echo "$url" | python -c 'import sys,urllib;print urllib.quote(sys.stdin.read().strip())'