Tag Info

Hot answers tagged

6

You have the alias statement when you don't need it, what you're actually creating is a function, replace the word alias with function and it will work as expected. You also don't actually need function either, you could just have the following and it will work as expected; genpass() { gpg --gen-random 1 $1 | perl -ne' print "Your password: "; ...


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 ...


3

You are almost there, just do it in the loop: awk '{for(i=2;i<=NF;i++){if(NR==1)h[i]=$i;else if($i>0.1)x[i]++}}END{for(i in x){print h[i]": "x[i]}}'


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 ...


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 ...


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

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 = []): ...


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 ...



Only top voted, non community-wiki answers of a minimum length are eligible