Tag Info

New answers tagged

1

First, refactoring your question: How can I construct a perl script that inputs data from snmpwalk for each IP/Host and outputs a table for each OID. Second, your example snmpwalk commands make no sense. It might make sense if OID were a variable. You problably mean to use snmpwalk -v2 -c public ${ip} ${OID} You could do something like this: ...


0

Awk solution awk ' /Routeur/{ i=0; host[$1" "$2]=$4; k++; param[k]=$5; next } { i++ Data[k,i]=$0 } END{ printf("%-12s%-15s","routerName","IPadd"); for(j in param) printf("%-17s",param[j]); print "\n"; for(h in host) for(i=1;i<3;i++){ printf("%-12s%-15s",h,host[h]); for(j ...


1

Perl solution, using Text::Table for nice output formatting: #!/usr/bin/perl use warnings; use strict; use Text::Table; my %t; my ($router, $ip, $column); while (<>) { if (/==>/) { ($router, $ip, $column) = /(.*) ==> ([0-9.]+) (\S+)/; } else { chomp; push @{ $t{$router}{$ip}{$column} }, $_; } } my @columns ...


0

You can do it with a one-liner by saving the last filed to a new variable, and then set it original pointer to a empty string, and then print $0 and last-filed variable you saved. (echo a b c 10; echo x y 2 ; echo x 1) \ | awk '{lastf=$NF ; $NF="" ; print $0,", "lastf}' \ | column -ts, # output a b c 10 x y 2 x 1


2

Here's a solution in awk that dynamically determines the required column widths. It can take any number of fields on each line, but it assumes the final field is an integer. The integers are formatted to line up on the right, as desired. format.awk #!/usr/bin/awk -f # Format text and numbers into two columns # Written by PM 2Ring 2015.04.16 #Gather data, ...


2

Change the column separator to e.g. Tab than use column: output | sed 's/\S\+\s*$/\t&/' | column -t -s $'\t'


2

glenn jackman's GNU/AWK answer is elegant but a little more simply is awk 'BEGIN {FS=OFS="\t"} match($5,/[0-9]+/,arr) {print $0,arr[0]}' file


1

With sed you can substitute by occurrence - so you just ask for the fifth <\tab>-delimited [1] field and for any numbers within it by ruling out other possible matches: sed 's/[^\t0-9]*\([0-9]*\)[^\t]*/\1/5' <infile After doing a copy to my clipboard of the other examples here I did: xsel -bo | unexpand -a | sed ... ...to unexpand -all ...


2

Using @John1024's sample text, this is GNU-awk-specific gawk -F '\t' -v OFS='\t' 'match($5, /[[:digit:]]+/, m) {$(++NF) = m[0]} 1' file produces 1 2 3 4 c.2458C>T 6 2458 a b c d c.45_46delAA or f 45 a1 b2 c3 d4 p.Ala78_Arg80del f6 78 Or perl perl -F'\t' -lane 'print join "\t", @F, $F[4]=~/(\d+)/' file


2

Based on your description, suppose that we have, as input, a tab-separated file like: $ cat file 1 2 3 4 c.2458C>T 6 a b c d c.45_46delAA or f a1 b2 c3 d4 p.Ala78_Arg80del f6 Using sed To find the first integer from the fifth column: $ sed -r ...



Top 50 recent answers are included