Questions tagged [perl]

Perl is a high-level, general-purpose, interpreted, dynamic programming language. It was originally developed by Larry Wall as a general-purpose Unix scripting language to make report processing easier, over a period with support from open source community, it has evolved and matured to be used for graphics programming, system administration, network programming, finance, bioinformatics, and other engineering applications.

Filter by
Sorted by
Tagged with
0
votes
2answers
103 views

while read line find – faster with perl?

I have a text file with three columns separated by tab and I read the third column line by line to find all files in a directory which have this in the name. Since it is a file with up to 1000 entries,...
0
votes
5answers
72 views

Can a shell script find all groups of consecutive lines matching the same regex and shuffle them?

I'm writing quizzes for my students in a markdown language. One of the quizzes might look like this: % QUESTION Who played drums for The Beatles? (X) Ringo ( ) John ( ) Paul ( ) George % QUESTION ...
0
votes
3answers
62 views

Range of lines in file

I have a file with a few o lines: C 1.31729690416596 -0.05166770188922 0.05026556004853 C 2.15676687192808 -0.87605403673920 0.93010807487406 C 1.45516592682388 -0....
2
votes
1answer
45 views

Interleaving two binary files by fixed-size blocks

We have paste(1) which can interleave files by lines. Out of curiosity, I wonder if there's some binary equivalent. It should copy the first N bytes from file A to stdout, then the first N bytes of ...
0
votes
1answer
28 views

Terminal warning or error

Every time i open up a terminal i do get the following message on the terminal Can't locate local/lib.pm in @INC (you may need to install the local::lib module) (@INC contains: /home/punit/perl5/lib/...
-1
votes
3answers
65 views

linux + print the root file system size

lvs is good command to show us the file system size as lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lv_root vgW -wi-ao---- 100.00g lv_swap vgW -wi-ao---...
1
vote
6answers
120 views

how to delete consecutive records if they have the same field using awk or sed?

Hi I want to delete the lines which contains the same numbers, how to achieve that in awk or sed or perl? For example, line 4 and 5 both contains 12.7, so I want both lines to be removed. Thanks. ...
1
vote
2answers
33 views

Distinguish multiple USB sound cards by USB port they're plugged in

What I want is to be able to consistently tell apart multiple USB sound cards, identify them by the USB port they're plugged in and use that knowledge to play a sound on a speciffic sound card in my ...
0
votes
2answers
31 views

Why does 'perl -F,' work differently from 'perl -F<space>'

This does what I expect (put --- when column2 changes value): $ (echo 'a,,b';echo 'b,,a';echo 'c,a,b') | perl -a '-F,' -pe 'BEGIN{$last="---\n";}{local$_=$F[1];if(($last)ne$_){print"...
0
votes
1answer
79 views

No recipient addresses found in header - Sendmail [closed]

From C shell script I am invoking a perl script to send an email, /path/send/email/email.pl "abc@gmail.com" | /usr/sbin/sendmail -t Perl script print "To: ".$ARGV[0]."\n&...
1
vote
4answers
48 views

Replace (one or) two different patterns in a file with regexp

Suppose an input.txt file that contains several strings as the following ones: [[foo>a|a]] [[foo>b|b]] [[foo>c|c]] that I'd like to replace by: :foo:`a` :foo:`b` :foo:`c` I guess I could ...
0
votes
2answers
53 views

How to check if 2 files are empty in perl using if condition

if(-z "$file1" && "file2") { print "file1 and file2 are empty"; } else { print "execute"; } When I write this, when the files are empty it prints ...
0
votes
3answers
77 views

Script for formatting code into columns

Often I have code that I want to align based on similar structure of lines, not just the left-side auto indent. Is there a script out there that can do something like this? Here is an example of ...
0
votes
1answer
12 views

Perl Tkx module works better through SSH tunnel than direct to X server

Trying to port an ActivePerl (on Windows) to a CENTOS Linux environment. I was startled to find that the perl Tkx module wasn't common beyond ActivePerl, and had to be installed from CPAN, and that ...
0
votes
1answer
42 views

why perl's if condition is satisfying empty string?

The below code works fine, except for the part the STDIN takes an empty value also and goes to first selection "print "Selected Y \n";". If I use && $check ne "" )...
1
vote
2answers
96 views

RE: How to insert text after a certain string in a file?

Referring to the link: How to insert text after a certain string in a file? I have this input file: Some text Random [option] Some stuff I want a line of text before "[option]": Some text ...
0
votes
4answers
110 views

How to replace every digit after special character '$' with '*' [duplicate]

I have a file which contain data like below Data in file : axbnx $56 ghjas $78$ axbnx $5** ghjas $ axbnx $006 ghjas $$678 Needed Output in below form : axbnx $** ghjas $**$ axbnx $*** ghjas $ ...
0
votes
0answers
7 views

Configure SPF for existing domains in DirectAdmin panel using BIND

I have a server runs the DirectAdmin panel and I want to add SPF record to all domains in the server What I did from this link is: cd /var/named mkdir /root/dbbackup cp *.db /root/dbbackup perl -pi -e ...
1
vote
2answers
50 views

Perl pattern match and substitute to replace only 4th word and retain everything else

I need to replace the 4th word on every line with 0: Original: R5_427 MMP15@2:S VDD:1 967.796 TC1=0.0004785156 R5_428 MMP15@2:S lninst_M55:S 0.001 Expected output: R5_427 MMP15@2:S VDD:1 0 TC1=0....
1
vote
1answer
26 views

/home/biol/perl5: Is a directory

the below script crashed: #!/bin/bash #usage: sh oxford_pbs.sh ref.fa AA.fasta hybrid.gff3 cov=50 ide=100 for ((i=70;i<=${ide};i++)); do input=$(basename $(echo ${2} | sed 's|.gff3||g')) #...
1
vote
3answers
438 views

Perl script from Ubuntu doesn't run on Debian

I have a Perl script which I created on Ubuntu 20.04 LTS. It's okay and works. I took this script on another machine with Debian on it. It doesn't run with: ./my_script.pl This gave me: ./my_script....
2
votes
3answers
402 views

How to escape ' inside " in perl?

I'm using the following script, but getting unexpected output. perl -pi -e '/DB_CHARSET/ and $_.="define('SOMETHING'/, true);\n"' file.txt This command adds define(SOMETHING, true); Since ...
0
votes
2answers
51 views

Delete a line with perl in bash script

This command: sed -i "\|^pref\.fullscreen\.toolbarPixels|d" ~/.vmware/preferences Works. But this command: perl -pi -e "\|^pref\.fullscreen\.toolbarPixels|d" ~/.vmware/preferences ...
0
votes
0answers
33 views

Determine how many logins occurred for a certain user

I apologize in advance since perl scripting is new to me. I'm trying to create a perl script that will determine how many times I have logged in to the system. I will need to use the following ...
0
votes
3answers
80 views

Changing the first letter after ] to uppercase [duplicate]

I have a CSV file in which I have thousands of lines like this: bla bla blab [FR] john is bla bla bla [US] blue house in Chicago... [ES] accessing the safe... bla bla See the elements between [ ]? ...
0
votes
1answer
34 views

Concat line with next line if both contain the same number of a specified character

I need to concat lines which contains a specified number of the specified character. I don't have any idea, it's easy in python or ruby, but I want to do this using perl / sed / awk / bash, without ...
4
votes
1answer
62 views

OpenSSH session is killed when from Perl a syswrite call is made with an empty variable in Solaris 11

We have a strange problem in Solaris 11.4. The problem arise when a code as the following is run from Perl my $emptystring = ""; syswrite STDOUT, $emptystring; The execution of a syswrite ...
3
votes
5answers
471 views

Elegant way to merge lines with multi-char-delimiter, ignoring blank lines, supporting \n, \r or \r\n

I want to read a multi-line file in a bash script, using the file path from a variable, then merge the lines using a multi-char delimiter and save the result to another variable. I want to skip blank ...
-1
votes
1answer
42 views

Need a sed or perl command to replace line that starts with certain text

I am looking for either sed or perl command to find a line in a file on multiple servers that begins with certain text and then replace the entire line. These lines will always start with the same ...
4
votes
1answer
100 views

Process substitution with Perl script

I have a Perl script which requires the following arguments: count.pl OUTPUT_FILE INPUT_FILE What I want to do is to use process substitution instead of specifying INPUT_FILE explicitly, for instance:...
0
votes
5answers
676 views

How to achieve an early exit from a code block in a bash script (analogous to perl's `last` directive)?

One feature of Perl that I really like is its generalization of looping control keywords to any curly-brace-delimited lexical block1. For example, one can use Perl's last directive to exit any such ...
0
votes
1answer
20 views

Rounding numbers of a CSV file, skipping the header

This question is a derivative of the https://askubuntu.com/questions/601149/is-there-a-command-to-round-decimal-numbers-in-txt-files, which was successfully solved by using: perl -i -pe 's/(\d*\.\d*)/...
1
vote
2answers
51 views

How to remove duplicate paragraphs

Given a file with paragraphs (group of lines separated by a blank line). It is guaranteed that the line breaks within equivalent paragraphs are conserved. Is there a way of using uniq to remove the ...
0
votes
0answers
20 views

Does perl ftp class works?

I have this simple script: #!/usr/bin/perl -w use Net::FTP; $ftp = Net::FTP->new('apache.cs.utah.edu'); $ftp->login('anonymous', '-anonymous@') or die "login\n"; $ftp->cwd('/apache....
0
votes
1answer
65 views

Escaping nested double-quotes in a corrupted CSV file

I have a large corrupted "CSV" file with many nested double-quotes. For instance: 123,"I wonder how to escape "these" quotes with backslashes.",123,456 456,"I wonder ...
-1
votes
1answer
55 views

Perform calculations on tabulated results and print the results in tabulated form

I have a report which displays the clock periods along with the clock names and duty cycle. Now, I would like to use tcl or awk or perl to make it display with clock period interms of freq and the ...
0
votes
0answers
77 views

Errors when launching urxvt

I installed urxvt via the universe repo on Elementary OS ( Ubuntu bionic base) and when I try to launch it from the terminal I get these error: urxvt: perl extension 'clipboard' not found in perl ...
1
vote
2answers
179 views

Convert a textual representation of a float to actual numeral using command line

I have a double printed as text. Is there a way to pass that source text number to some utility in order to get the actual numeral i.e. the nearest actual representable double value? Either in decimal/...
0
votes
1answer
62 views

the output of a perl script which calls “sudo lsof | grep username | wc -l” differs in cron vs manually

We are having issues with a perl script we run for file count: #!/usr/bin/perl $stat=`sudo lsof | grep username | wc -l`; $date=`date '+ %Y/%m/%d-%H:%M:%S'`; $exit=`echo $?`; if ( $...
1
vote
2answers
42 views

perl cannot `exec` to binary

In my fresh installation of Debin, perl intepreter is installed by default (in other words, I have no other perl packages yet). However, trying this: $ls a.cpp b.cpp $ perl -e 'system "g++ -o a....
1
vote
2answers
46 views

How to implement string to array hash in perl?

I am trying to count occurrence of each word on particular line of input. Given example (what I am trying to achieve): $./foo.pl asd fgh asd iop zxc asd: 1, 2 fgh: 1 iop: 2 zxc: 3 Just a program to ...
1
vote
0answers
33 views

SpamAssassin: UTF-16 surrogate 0xd800 at /usr/local/share/perl5/Pod/Simple/BlackBox.pm line 67

When my Spam Assassin cron job runs, it gives Perl error messages which are then emailed to me by the cron daemon. How can I fix this error or warning? Cron job: /usr/share/spamassassin/sa-update.cron ...
0
votes
0answers
18 views

Mail::SPF: Uncaught error: long domain label at /usr/local/share/perl5/Error.pm line 37

I cannot update Mail::SPF package. When I run cpan Mail::SPF it fails with this error. It looks like a Perl error instead of an error with the package. I have Perl 5.10.1, the latest in Yum for CentOS ...
0
votes
4answers
106 views

how to capture parameter and value from line

we want to capture only the parameter - segment.bytes and his value example echo "$info" | grep "segment.bytes" {"version":1,"config":{"segment.bytes":...
0
votes
1answer
66 views

Why won't Yum install the latest version of Perl?

Why won't Yum install the latest version of Perl? I see that Perl is at 5.32.0 https://www.perl.org/get.html. My Perl is 5.10.1. # perl -v This is perl, v5.10.1 When I try to update, it doesn't do ...
1
vote
2answers
43 views

How to align only one line in file to the left side with sed or perl one liner

This will delete all spaces and tabs at the beginning of every line: sed 's/^[ \t]*//' file but lets say we want to align only the parameter queued.max.requests=1000 from file Example input: log....
0
votes
1answer
42 views

What does \L$2 mean in perl rename tool?

I see this command advised, whenever a person asks online about renaming all uppercase files to lowercase: find "$(pwd)" -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \; I understand ...
0
votes
4answers
131 views

Convert all Unix timestamp (in milliseconds) in a generic text file to human-readable date

I want change Unix epoch (in milliseconds) to normal date in a generic text file. I accept bash, sed, awk or perl solutions. Example file1 (only numbers with 13 digits are dates): Foo bar ...
0
votes
5answers
57 views

Count characters in two specific lines in all files and printing the sum with corresponding filename

Following is the case: there are multiple *.txt files each containing below lines with different values of var or lab. For example: abc.txt: var^ABCDEFG lab^ABCDEFGH def.txt: var^ABCDEFGHI lab^...
0
votes
6answers
108 views

Split each line by a delim read from another file and store all split word compounds in the result file

I want to split each line from file names by each and every delimiter from file delim and store the unique word compounds into result file compounds. Lines from names that were not split should be ...

1
2 3 4 5
25