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.

1
vote
2answers
82 views

How can I extract only the pid column and only the pathname column in the lsof output?

$ sudo lsof -u t | grep -i "\.pdf" evince 1788 t 37r REG 8,4 176328 134478 /home/t/some/path1/white space/string1 + string2 string3.pdf evince 3737 t 36r ...
2
votes
1answer
170 views

Perl run command on remote system

I need to run a series of commands on remote systems, but am having problems with perl staying logged in. I "can't" use the ssh or telnet command, as it is a service account logging in and has no ...
0
votes
5answers
133 views

How to replace new line \n and upcoming + sign with space

Replace new line \n and upcoming + sign with space input file ABC + DEF foo + bar Output should be ABC DEF foo bar
0
votes
3answers
119 views

how to remove the empty/blank lines from files that appears as @ from vi

when I open file by vi as vi file Current partition replica assignment @ @ @ @ @ {"version":1,"partitions":[{"topic")] @ @ @ @ @ Proposed partition reassignment configuration but I try to delete ...
1
vote
4answers
91 views

add a new column with sum of columns in perl

I have a huge text file which has below columns col1 col2 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec abc dec 10 20 30 40 50 60 70 80 90 11 12 13 The output I am looking for is an addition of ...
0
votes
1answer
44 views

awk + count the strings from file [duplicate]

I have in file /tmp/users list of users ( each list contain diff users ) Example more /tmp/users root kafka yarn hdfs root root yarn moon apache start moon apache I want to print the users that ...
-1
votes
1answer
178 views

Perl script not found when executed from a different directory than the current one

I am using perl64 on Windows 10 with UWIN installed. I wrote a perl script, sv2jb.pl, which runs fine when invoked under ksh by just typing its name, and when it is in the current directory. I then ...
0
votes
0answers
14 views

How to create separate files based on first column value? [duplicate]

It is tab separated 3 column file. I need to create separate files based on first column value Input: 194501 CAD 1.47421052631579 194517 CAD 1.39578947368421 194520 CAD 0.949473684210526 194501 ...
-2
votes
1answer
57 views

how to match single pattern and replace it with multiple pattern in perl [closed]

i have one file which contain following info - input - a[1]= something_data_1; a[2]= something_data_2; a[3]= something_data_3; so i want to replace that "a" with different pattern like below, ...
1
vote
1answer
492 views

mkdir command not found?

I think I messed up the PATH. I was installing Bioperl and tried to changed path. The correct code should be: $ export PATH=/usr/local/ActivePerl-5.26/bin:$PATH $ export PATH=/usr/local/ActivePerl-5....
1
vote
1answer
35 views

How to prevent from destroying symlinks, using Perl when to replace with sed regex?

Based on How do I prevent sed -i from destroying symlinks?, but I use Perl. I tried by middle of all these questions: Is there a way to make perl -i not clobber symlinks? perl symlink on gz file How ...
1
vote
1answer
42 views

Disable Tomcat Session persistence using sed or perl

I need to disable Tomcat session persistence as I have implemented SpringSession on my Spring (not Spring Boot) Application. I've tried using sed and perl to edit multiple lines in the context.xml ...
1
vote
2answers
65 views

How to start a new column after every nth row?

I have a file (comma separated) on a Linux system with 3 columns. I want to start new column after every 4th row. Input: col1,col2,col3 1,disease1,high 1,disease2,low 1,disease3,high col1,col2,...
0
votes
1answer
26 views

Remove non-alphas while ignoring certain unicode chars

I have a text like the following: []përgjithshme [" është "] 28.748 [< kilometra katrorë.>] This text contains cyrillic characters in the range U400 - U4FF. I want to strip out the non-...
0
votes
0answers
37 views

Script can not write into dierectory

I have configured apache web server on fedora 29 , perl script that generates web page with current NIC information (state , speed , mac , etc.) and traffic graph. Script generates the web page and ...
0
votes
1answer
68 views

tracking segfault upon invocation of perl script (mytop tool and similar)

on my gentoo machine, mytop 1.9.1 quits upon invocation with the following output: # mytop Useless use of private variable in void context at /usr/bin/mytop line 1001. "my" variable $data masks ...
4
votes
3answers
365 views

Manipulating text in first column only? [duplicate]

Example Input: foobar@example.com foo@example.com,bar@example.com Example Output: foobar@example.org foo@example.com,bar@example.com So, in "normal" circumstances, it would obviously be easy to do ...
1
vote
5answers
201 views

Remove text between consecutive occurences of strings

I need to remove all text between two given strings in a text file. The strings may be located on different lines. For instance, in the following text file @article{ginsberg_lifespan_2018, title =...
0
votes
1answer
42 views

how to add words before line on all the scripts in current folder

under /home/scrript , we have 187 bash scripts all the scripts have the following line: kill -PIPE $PID we want to add the following words before this line on all the scripts as the following [[ $...
0
votes
1answer
74 views

Get lines of file matching a regex

Is there a more compact way to get lines of a file that match a regex than the following? open my $fh, '<', $file or die "Cannot open $file: $!"; while ( my $line = <$fh> ) { next ...
0
votes
2answers
872 views

Check which process is using most memory and summary total used memory

by the following command we can check which process is using most memory as we can see the first field show in MB the used for each process is it possible by awk to sum all the numbers and to get ...
0
votes
1answer
56 views

Insert new text in the middle of a file replacing old text without re-inserting the same things over and over?

I have a file that I want to update relatively frequently. What needs to be done is that a specific part of the file would be changed to include some more lines. I am doing it with sed and \a option: ...
0
votes
1answer
219 views

Print line and following text based on pattern matching

I am trying to filter lines from a text file based on patterns in proceeding lines which keeping the pattern matched line. I also need to rename the pattern matched files for example: >text chr1 ...
0
votes
1answer
82 views

Perl script for generating MAC addresses

This perl line very useful to change mac address but retain the first three pair. perl -e 'for ($i=00;$i<6;$i++){@m[$i]=int(rand(256));} printf "00:16:3E:%X:%X:%X\n",@m;' Generate some good ...
4
votes
3answers
304 views

Get one thing from a line and concatenate it with one thing from another line

I have the following: 2018-11-10 23:57:21 [COMMAND]: sar -u 10 5 AIX host 1 7 11/10/18 System configuration: lcpu=64 mode=Capped 23:57:21 %usr %sys %wio %idle physc 23:57:31 ...
5
votes
2answers
502 views

Perl command line regex to modify all pattern matches

I'm trying to use some arithmetic over the matched patterns in perl command line. I'm able to do it for one match but not for all. str="a1b2c3" perl -pe 's/\d+/$&+1/e' <<<"$str" a2b2c3 ...
1
vote
2answers
130 views

Install custom perl modules

I have build an RPM from a proprietary software collection in a CentOS 7 environment but the build process required executing some Perl modules (.pm files) found within the source itself. When I ...
2
votes
0answers
34 views

How do I display file modification time (linux) as “Nov 8 12:00” format? [duplicate]

The format I want is "Nov 8 12:00". It is the format you get by using the ls -l command. It is month, day of the month, hour and minute. I tried stat -c %Y filename which gives time of last data ...
2
votes
1answer
77 views

Can I change terminal type used to login through Net::SSH in perl?

When I login on some particular server through Net::SSH in perl (which I do not have admin access to), I get the following error: %SECURITY-SSHD-4-WARNING_LOGIN : The requested term-type '' is not ...
1
vote
3answers
142 views

Find or extract text between two patterns either on the same line or in many lines

I need to print the text between two patterns without keeping in mind their place as they are found randomly across the file. either in the same line or not in the same line or a text occur between ...
0
votes
1answer
45 views

Replace any string after the last dot with txt string

how to replace any string after the last "." to txt for example filter.bash sum.sh portG.py run.doK.ksh expected results filter.txt sum.txt portG.txt run.doK.txt
1
vote
1answer
38 views

edit names in phylogenetic tree in newick format [closed]

I have a phylogenetic tree in newick format, and I would like to remove some fragments of the name of the taxa, 1_[genus_specie_1]_characters:0.2654682758,(((((((((((((((2_[genus_specie_2]...
0
votes
0answers
378 views

Perl v5.10.0 required--this is only v5.8.8, stopped at ./Configure line 12

when I try to configure new openssl package(openssl-1.1.1), I am getting that perl error.New openssl has dependency on perl version of 5.10.1. My build machine has two versions of perl -5.8.8 and 5.10....
0
votes
2answers
108 views

How to swap two fields inside a JSON file

I have a file like this {"100":["0.00001","10","0.01"], "101":["0.0001","100","0.1"], "102":["1","1000","1"], .... "103":["0.01","10000","10"]} I want to swap the second number with the third, ...
1
vote
3answers
1k views

split string to two parts using sed or awk or perl or bash

I have string like this: Grades ABCDEF-123456 I want to split this string to two sections like this Grades ABCDEF Grades 123456 How can I do that in bash?
0
votes
2answers
63 views

how to print the matching value from same line, which has multiple Delimiter?

I have a File under Linux /tmp/volume.log and the content is: [id:1091666, name:root, deviceName:/dev/sda, maxStorage:107374182400, unitNumber:0, displayOrder:0, rootVolume:true],[id:1091851, name:/...
-3
votes
3answers
148 views

How to grep or search 3 word Patterns in a file and print them along with the content between second and third word Pattern [closed]

How to find or search word PATTERN1 and PATTERN2 and print them both later i want to search PATTERN3 and Print the whole content or section between the search PATTERN2/PATTERN3 (Note Pattern1/2/3 ...
2
votes
3answers
237 views

Filtering list of numbers containing sequential digits

I would like to filter many text files. Each file contain a very long list of numbers. Filtering the files must occur by the number of the consecutive digits within each number. Example list form ...
6
votes
2answers
681 views

Perl script running infinitely - how to debug what happened?

I am running a Perl script on a Linux machine via a cron job. However, from time to time (around 1% of all cases), the script gets stuck and runs infinitely. If I list processes, I can see its PID. ...
0
votes
4answers
57 views

Apply if condition to all lines of a tab delim file which have same value in a particular column:

Basically I want to apply if condition in lines which have same value in column2. In example first three lines have same value in column2 (Disease1 ). Now for these three line I want to apply IF ...
-1
votes
1answer
54 views

Perl Script Output in Excel / Text file in Solaris 10

I have a perl script, I am not able to get output of script in an excel or text file format. Can someone please help me figure out that ? perl -MPOSIX -e ' opendir D, "." || die "open .: $!\n"; ...
0
votes
1answer
31 views

Random reading from file (perl)

In this section of code I need to read from file.txt randomly: ... open my $fh, '<', 'file.txt' or die $!; while ( <$fh> ) { next unless /\S/; chomp; my $response = $ua->get( "http://$_....
5
votes
4answers
392 views

Summing rows in a new column using sed, awk and perl?

I have a file that contain numbers something like: 1 11 323 2 13 3 3 44 4 4 66 23 5 70 23 6 34 23 7 24 22 8 27 5 How can I sum the rows and output the results in a column, so the results are as ...
1
vote
5answers
1k views

How do I delete all lines in a file until it matches a string line pattern? [duplicate]

How can I delete lines in a file until it matches a string line pattern? cat test.txt The first line The second line The third line The fourth line pen test/ut The sixth line The seventh line I ...
1
vote
3answers
103 views

Delete newline characters between patterns

foo I love Stack Exchange bar Some junk lines foo Welcome to the world of Bash bar foo Elon Musk rocks Yes, there is no bar complementing foo at the end of the file The required output is I love ...
0
votes
3answers
138 views

awk/perl print palindrome if not between brackets

I have a file with a bunch of strings, one on each line. I want to find and print a string only if it contains a palindrome and that palindrome is not between brackets. Examples: abba[cdef]gh # ...
-1
votes
3answers
177 views

remove the lines in CSV that contain specific pattern on the second field

How to remove the lines in .csv file that second field contain the word content? example : ams-hbase-log4j,content:\n#LicensedtotheApacheSoftwareFoundation(ASF)underone\n#...
2
votes
2answers
72 views

Default variables in Bash

The default variable for loops in Perl is $_. Is there any equivalent of this in Bash?
4
votes
1answer
361 views

BEGIN {…}; in Perl [closed]

I have a perl-script: #!/usr/bin/perl BEGIN { print "That's BEGIN message\n"; BEGIN { print "That's BEGIN-2 message\n"; }; END { print "That's END message\n"; }; BEGIN { print "That's ...
2
votes
3answers
66 views

How to remove Inverse match pairs?

I want to remove duplicate/inverse match pairs from a text file. E.g., the file contains data like the below: 10 |Name1 |20 |Name2 20 |Name2 |30 |Name3 20 |Name2 |10 |Name1 <-- Inverse pair (...