Tag Info

New answers tagged

1

I found a solution using perl substring function echo leng-1323-006|perl -lpe 'substr($_, 5, 5) = "";' return correctly leng-006 I hve removed from position 5 the 5 bad characters include the -


1

POSIXly: $ sed -e 's/-[^-]*-/-/' file leng-001 leng-002 leng-004 leng-005 leng-006


2

Using sed: sed -r 's/(.*[a-zA-Z]{4}\-)([0-9]{4})/\1aaaa/g'


2

The 3pm section is not used anymore. It is defined as manual pages concerning modul packages of perl in an old version of the Debian Perl Policy, noteably in version 1.2. Here is a site where you can read that old deprecated policy (see §3.1 and §1.4). In the latest Debian Perl Policy it is defined in §2.4 that module manual pages should be installed in ...


3

Perl one-liner: perl -pe's/\[gene=([^\]]*)\K\]/$h{$1}++?"$h{$1}]":"]"/e' yourfile Explained: -p: execute the code for each line of the file (stored in $_) and print $_ at the end. -e: code. s/regex/replacement/e: Match regex and replace it with replacement on $_. The regex: /\[gene= # match [gene= ([^\]]*) # match anything but "]" and put it a ...


2

sed -n '/-\{10,777\}/,/^\s*Table:/p' LaTeX.doc If you wants newline after each table: sed -n '/^\s*Table:/G;/-\{10,777\}/,/^\s*Table:/p' LaTeX.doc or sed '/-\{10,777\}/,/^\s*Table:/! d;/^\s*Table:/G' LaTeX.doc


8

You have a space after \1 in your replacement, just remove that and you should be good perl -i -p -e "s/^(password[]*=[ ]*).*$/\1$passwd/" config.properties ^ Removed space here


2

I'll edit this if you update the question but I think you're looking for something like this: perl -007lne '@F=(/-{7,}.*?Table:.*?\n(?=\n)/gsm); print join "\n", @F' file.tex Explanation -007 : slurp the entire file -lne : add a new line to each print call, process the input file, and run the script given by -e. @F=(/pattern/gsm) : save all matches of ...


6

That's a typical job for tr: LC_ALL=C tr '\0-\10\13\14\16-\37' '[ *]' < in > out In your case, it doesn't work with sed because you're in a locale where those ranges don't make sense. If you want to work with byte values as opposed to characters and where the order is based on the numerical value of those bytes, your best bet is to use the C locale. ...


0

One piece of documentation I could find says only: LC_MESSAGES Specifies the locale to use for LC_MESSAGES category information. The LC_MESSAGES category determines rules governing affirmative and negative responses and the locale (language) for messages and menus. I could not find any documentation that mentions that "%l.%c" (presumably for ...


0

An optimization I would add to cuonglm's suggestions, if only to make the regex easier to maintain: m/^(?:[-+]?\d+\.\d+\s+){2}/ This way, you can concentrate any further optimizations to the regex in one place. Also, if you know that the numbers are proper decimal numbers (i.e. your data doesn't contain more than one decimal dot in a string of digits): ...


2

Base on your output, I offer some points to improve your regex: You can match explicit at beginning of line, using ^ If you don't use the match groups, then you don't need parentheses or using non-capturing group ?: \s includes \t, so you only need \s. The final regex can be m/^(?:[+-]?\d+\.\d+)\s+(?:[+-]?\d+\.\d+)/


1

it matches lines that begin with two optionally signed numbers having decimal parts, with said numbers separted by ascii whitespace. it seems optimal and clear as it stands.


1

It is a bit more complicated than it seems - there's probably a library that would do this better (there's a lot of maths libraries in perl). But this should do approximately what you want: #!/usr/bin/perl use strict; use warnings; #read file 1 open( my $file1, "<", "data1.txt" ) or die $!; my $header_line = <$file1>; chomp($header_line); my ( ...


3

Nagios::Plugins was renamed to Monitoring::Plugins due to trademark reason. cpan doesn't index Nagios::Plugins anymore. Now you must install Monitoring::Plugins: perl -MCPAN -e 'install Monitoring::Plugin' Further reading https://rt.cpan.org/Public/Bug/Display.html?id=102080 https://www.monitoring-plugins.org/news/new-project-name.html


4

This is a standard problem of finding connected components in an undirected graph. Since you tagged your question with perl: #!/usr/bin/env perl use v5.10; use strict; use warnings; use Graph::Undirected; my $g = Graph::Undirected->new; while (<>) { chomp; $g->add_edge( split /\t/ ); } for ( ...


0

for f in ???.txt do awk -f program.awk "$f" > "output$f" done will process all files whose names are three characters (any characters) followed by .txt.  To restrict it to only files whose names are three digits followed by .txt, use for f in [0-9][0-9][0-9].txt


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



Top 50 recent answers are included