Tag Info

New answers tagged

0

You can't. mech-dump simply does not support it: my $uri = shift or die "Must specify a URL or file to check. See --help for details.\n"; if ( -e $uri ) { require URI::file; $uri = URI::file->new_abs( $uri )->as_string; } ... my $response = $mech->get( $uri ); It simply will try to fetch whatever is given as an argument, and fail if ...


2

This feels like it could be done in a simpler way, but the best I can come up with after an hour of head-scratching is this python script: #! /usr/bin/env python3 import sys, os class Block: block_id = '' source1 = '' source2 = '' mixtures = [] def __init__(self, block_id = '', source1 = '', source2 = '', mixtures = []): ...


0

Slow day at work, so here's a python solution python3 -c 'import sys x = (l.partition("\t") for l in sys.stdin) x = ((l[0].split(";"), l[1] + l[2]) for l in x) for a in x: print(*a[0], sep=a[1], end=a[1]) ' <file


0

Yes, this is not perl, but I like GNU awk for this awk -v RS='[[:space:]]+' 'BEGIN{max=-inf};{max = $0>max? $0: max};END{print max}' file 63


2

If you wanted to support different sorts of numbers (-2, 1E-20, inf, 0x2f, 0b0101, 0777...), not just positive decimal integer ones, you could do: perl -lne ' while (m{(?!<\w)(?:(0x[0-9a-f]+| 0b[01]+| 0[0-7]+)| [-+]?(\d+(\.\d*)?|\.\d+)(e[-+]?\d+)?| infinity|inf)(?!\w)}xgi) { $v = defined($1) ? oct($1) : ...


-2

grep '[0-9]*' number.sh | sort -rn | head -1


0

Longer Perl version, that allows you to access the data per key and further process if required. This does also not use capturing from regular expressions. #!/usr/bin/perl use warnings; use strict; my %hash; while ( my $line = <> ){ #splitting the line into two parts at the first TAB. my ($keys, $value) = split (/\t/ , $line, 2); ...


1

Another Perl one-liner. $ perl -pe 's/^([^;]+);([^;]+);(\S+)\s+(.*)/$1 $4\n$2 $4\n$3 $4/' file K00001 0 0 34 0 0 0 0 0 0 0 0 0 0 0 0 0 36 0 0 52 0 0 0 6 0 K00004 0 0 34 0 0 0 0 0 0 0 0 0 0 0 0 0 36 0 0 52 0 0 0 6 0 K00008 0 0 34 0 0 0 0 0 0 0 0 0 ...


3

With sed: sed 's/^\([^[:blank:];]*\);\([^[:blank:]]*\)\(.*\)/\1\3\ \2\3/;P;D'


3

This should do what you want. Basically, we put the first field (the keys) in $k and the rest of the fields in $f by splitting on \t and limiting the split to the first 2 fields. Then we split the keys on ; and print each key along with the remaining fields on its own line. perl -nle '($k, $f) = split "\t", $_, 2; print "$_\t$f" for split ";", $k' -n ...


4

You can use awk to split the first column: ~$ awk '{split($1,a,";"); $1="";for (i in a){print a[i],$0}}' myfile K00001 0 0 34 0 0 0 0 0 0 0 0 0 0 0 0 0 36 0 0 52 0 0 0 6 0 K00004 0 0 34 0 0 0 0 0 0 0 0 0 0 0 0 0 36 0 0 52 0 0 0 6 0 K00008 0 0 34 0 0 0 0 0 0 0 0 0 0 0 0 0 36 0 0 52 0 0 0 6 0 You split the first column on ; (split($1,a,";")) and then you ...


2

the awk file { split($1,A,";") ; for ( a in A ) { printf "%s",A[a] ; for(i=2;i<=NF;i++) printf "\t%s",$i ; printf "\n" ; } } where split($1,A,";") put into A all the sub filed of $1 for ( a in A ) loop through value of A printf "%s",A[a] ; print the first value for(i=2;i<=NF;i++) printf "\t%s",$i ; print remaining ...


0

perl -i.bak -nle 'print unless /^[0-9]{0,9}$/' file You asked for zero length numbers (ie. empty lines) to be removed also.


0

Based on those 1st 3 messages it would look like you need to upgrade your version of Perl to at least 5.12.3. Perl version 5.012003 (5.12.3) is at least recommended to run ASSP 2.4.3 (14313) - you are running Perl version 5.010001 - please upgrade Perl Perl version 5.012000 (5.12.0) is at least required to use the unicode Bayesian/HMM engine of ASSP ...


0

perl -h is useful -e program: one line of program (several -e's allowed, omit programfile) -p: assume loop like -n but print line also, like sed


0

This is more portable, since some of the other answers depend on href being the first element grep -o href.*\" file.txt | cut -d \" -f 2


3

In addition to @St├ęphane Chazelas's answer, we don't have to worry about this issue if we use -i command line option: $ perl -pe '' 'uname|' Linux $ perl -i -pe '' 'uname|' Can't open uname|: No such file or directory. Because when using -i option, perl used stat to check the file status before process it: $ strace -fe trace=stat perl -pe '' 'uname|' ...


14

What's the problem First, like for many utilities, you'll have an issue with file names starting with -. While in: sh -c 'inline sh script here' other args The other args are passed to the inline sh script; with the perl equivalent, perl -e 'inline perl script here' other args The other args are scanned for more options to perl first, not to the ...


0

First of all, you can use almost the exact same regular expression and syntax as you did with sed. Just change & to $& for Perl: echo "WARN ERROR foo" | perl -pe 's#WARN#\x1b[33m$&#; s#ERROR#\x1b[31m$&#; s#foo#\x1b[32m$&#' Or, using your original Perl approach, just remove the .* on either side of the pattern you want to ...


1

Here's an example that highlights from ERROR to the end of the line, the whole line containing WARN, and foo but nothing surrounding it. Only the first matching rule is applied (e.g. WARN: ERROR foo sets ERROR foo in red), tune as you see fit. perl -pe 's/ERROR.*/\e[31m$&\e[0m/ || s/.*WARN.*/\e[33m$&\e[0m/ || s/foo/\e[32m$&\e[0m' An ...


3

Just install the missing module in the standard way. cpan Shell



Top 50 recent answers are included