New answers tagged

0

awk '{arr[$1]++} END {for (i in arr) {if (arr[i]==1) {print i} }}' 1 grapes lime peach


0

Or, to show all different line: sort test.data | uniq


4

That's the job for uniq: $ LC_ALL=C uniq -u file grapes lime peach If you want other tools, like perl: perl -nle '$h{$_}++; END {print for grep { $h{$_} == 1 } %h}' <file


0

Try this AWK! awk '{a[$0]++} END {for (x in a) if (a[x] == 1) print x}'


2

How many lines are in each file. Use wc, originally for word count, I believe, but it can do lines, words, characters, bytes, and the longest line length. The -l option tells it to count lines. wc -l <filename> This will output the number of lines in : $ wc -l /dir/file.txt 32724 /dir/file.txt You can also pipe data to wc as well: $ cat ...


0

Depends how precisely you want the formatting - usually tab separated is enough - but I'd tackle it like this: #!/usr/bin/env perl use strict; use warnings; #set record separator to double line feed. local $/ = "\n\n"; #print header row print join "\t", "VM", "Virtual_Disk", "size", "Physical Disks", "\n"; #iterate stdin or files specified on ...


0

perl was designed and made for precisely this kind of problem. It's nickname was "pathological eclectic rubbish lister". Read the documentation on perlform. What you do is read your data (say, line at a time), parse it, stuff into variables, then issue the command write which outputs the current data based on a format which you defined. For your data you ...


0

Probably when you do cpan its not doing configure correct Carton I think you should try cpanm Carton cpanminus (cpanm) is an attempt to make a zero-configuration client that automatically does the right thing for most users.


0

Actually, just take the default (remove the second parameter). See https://metacpan.org/pod/IO::Socket::SSL (search for SSL_version). The default is SSLv23:!SSLv3:!SSLv2. I modified line 1906 in v1.56 to read # if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'SSLv3 TLSv1')) { if (! IO::Socket::SSL->start_SSL($SERVER)) { (just ...


2

One possible way to do it would be to use perl's unpack function, with a template constructed from the first line of the file. After removing whitespace, it uses a regular expression with a repeating backreference to find the longest contiguous strings of identical characters not exceeding the given maxwidth, and stores their positions in an array. The ...


2

Other variant with awk awk ' NR==1{ for(i=2;i<=NF;i++){ count++ if($(i-1)!=$i || count>4){ D[i]=1 count=0 } } } { for(i in D) $i=" "$i print } ' OFS="" data.file >new.file And sed sed -re ' s/ ...


3

Here's an awk script. You just change the number 5 to have other groupings. awk ' NR==1{ previous = $1 for(i = 1;i<=NF+1;i++) if($i!=previous){ col[++numcol] = i previous = $i } } { j = 1; start = 1 for(i = 1;i<NF;i++){ printf "%s",$i if(i==col[j]-1){printf " "; start = col[j++]} else if((i-start+1)%5==0)printf " " } ...


1

This is similar to choroba's answer $ cat file 1 1 1 1 1 1 1 1 2 2 2 2 3 3 3 3 3 3 2 4 5 8 9 10 13 17 19 29 30 32 33 50 700 800 900 950 $ perl -ane ' if ($. == 1) { for (($n,$i,$j) = (1,0,0); $j < @F; $n++, $j++) { if ($n == 3 || $F[$j] != $F[$j+1]) { $i-- if $i == $j; push @pairs, [$i, $j]; ...


4

Perl to the rescue! #!/usr/bin/perl use warnings; use strict; my $group_size = 3; my @first = split ' ', <>; my @groups; my $start_index = 0; while ($start_index < @first) { my $step = 1; while ( $step < $group_size && $start_index + $step < @first && $first[$start_index] == $first[ ...


0

This will replace "alpha" ocurrences that have numbers as the following word: perl -wnl -e 'if ( $_ =~ m/alpha-[0-9]/) {s/alpha/beta/g, print $_ }' foo.txt foo.txt before conversion: alpha-1 alpha-2 alpha-3 alpha-4 alpha-5 alpha-6 alpha-7 alpha-8 alpha-9 alpha-900 alpha-test alpha-word alpha-wadawadawada after: beta-1 beta-2 beta-3 beta-4 beta-5 ...


2

For automatic login, the way to go is using key-based authentication. A nice tutorial here You can then use the default one (the one in the ~/.ssh/id_rsa ) or use another key passing -i MyKeyFile parameter to ssh.


0

Use sshpass $ sudo apt-get install sshpass Create your script #!/bin/bash user="user" psswd="password" port="22" host="domain.com" sshpass -p $psswd ssh $user@$host -p $port Execute $ bash connect_script.bash Welcome to Ubuntu ..... LTS (.......) * Documentation: https://help.ubuntu.com/ New release '14.04.1 LTS' available. Run ...


5

The only thing you need to add to your one-liner is the option to slurp the file as a single string: perl -0777 -p -i -e 's/john paul\s*george/pete/g' ~/foo # ^^^^^ See http://perldoc.perl.org/perlrun.html#Command-Switches


3

With sed you can do this without slurping the entire file: sed -e ':top' -e 's/john paul[[:space:]]*george/pete/g;$b' -e '/john paul[[:space:]]*$/!b' -e 'N;btop' input This is much lighter on memory usage; it only slurps multiple lines when there is a possibility of a multi-line match starting from the current line. And then it only slurps until either ...


4

perl's -n and -p options put variants of while (<>) { ... } around your program, which makes them process input linewise. If you want to replace across multiple lines, you need to read the whole thing into a string, which you need to do yourself. perl -e 'local $/;$_=<>;s/john paul\s*george/pete/g;print' This undefines $/, the record ...


1

If you still get a certificate error after fixing the SSLversion as shown above, you need to disable certificate checking: if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'SSLv23:!SSLv2', SSL_verify_mode => 0)) {


4

Oneliner in Perl (thanks terdon!): perl -0 -pe 's/\s+(\S+)-(<\/page>\s+<page>)(\S+)/$2$1$3/g' filename What it does: matches against regular expression, and uses parts matched to reconstruct your word.


3

Some kind of a monster) With perl it should be easier cat file ba bla bla hyphe-</page> <page>nated bla bla bla and the output should look like bla bla bla</page> <page>hyphenated bla bla bla It's GNU sed (in some other sed-s -E option is used for extended regular expressions) sed -nr '/[[:alpha:]]+-<\/[[:alpha:]]+>$/{ N ...


0

xsl file is not that easy to handle directly, but I think you can convert it to csv file first, and then: paste -d ',' File1.csv File2.csv > onefile.csv The onefile.csv will be in the form you want.


1

If your intent is to check whether a particular command is available, you should do so instead of trying to execute it: if command -v spamegg >/dev/null; then echo spamegg is available else apt-get install spamegg fi Trying to execute spamegg to see if it's available is a bad approach. First, it obfuscates your code, making it look like spamegg is ...


1

IMHO, I don't think your approach is the best way to tackle this problem. The reason being is just because a command returns not found, doesn't mean the program isn't installed. It could simply indicate that the program is not located in any of your PATH locations. Perhaps, a better way would be to this is actually check against the list of installed ...


1

# example you need wget and your PATH is okay then: # bash/ksh/.. will return exit code 127 if command not found # # redirect stdin and stderr to the /dev/null = if exist, # output is not interesting wget --help >/dev/null 2>&1 stat=$? # variable ? include last command exit status echo "exit status:$stat" if ((stat == 127 )) ; then # not exist/found ...


8

Yes. $ spamegg spamegg: command not found $ echo $? 127 You could just do: if software --version &>/dev/null; then ## True, do something else ## False, do something fi



Top 50 recent answers are included