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.

0
votes
0answers
3 views

File read, compare and replace based on comparison in text file

Hi i need guidence to write code for file processing. i have one file which having ~ as delimeter and each line is keyword is 1st column. First i have to find the lines which matches with ^6999 Then ...
0
votes
2answers
37 views

How to Aggregate and get group count in specific column from text file by perl?

I have a big text file(with 15 lines) in this format (srip dip sport dport .....) I would like to group distinct first column and get the group counts, input file: 10.10.10.1 10.10.66.150 60761 502 ...
-1
votes
4answers
53 views

Compare 2 Files and Display Matched records

I really need your help Guys, I am new here in Unix. I want to compare my File2(3 column) to my File1(raw data), and save the result in a new file. But my files have a different delimiter. Example: ...
2
votes
2answers
49 views

Templated read (like scanf)

I've got a shell script variable, which currently is defined like this: tsource=/backup/%HOST%/%SHARE%/%PERIOD% I want to match this template to another variable, which might have a value like this: ...
0
votes
2answers
28 views

Returning wrong results in perl script [duplicate]

I am running this command on linux shell it works smoothly sed -i 's/\[-.*-]//g' error .txt What it does is it removes patterns like [-any text-] along with the brackets and - sign. but when I try ...
0
votes
3answers
83 views

perl regex - How to match foobar that does not begin with (\s*//\s*)

Basically I want to find foobar on uncommented lines like: // foobar # do not match me foobar # match me otherfoobar # do not match me To match the commented lines I use this: ^(\s*//...
0
votes
1answer
37 views

Getting Error with system() in perl

' Number found where operator expected at ./scripttemp.perl line 5, near ""sed -i -r "4" (Missing operator before 4?) String found where operator expected at ./scripttemp.perl line 5, near "}" ...
-2
votes
0answers
32 views

Using Grep in perl script [closed]

I want to execute the grep command inside my perl script. this is my command : grep -nr "{+" error.txt > error1.txt I want to find this character in file error.txt and want to print the line ...
1
vote
2answers
65 views

How to merge lines (of a multi-line code routine)

I have a file; contents are as follows: cat -n /tmp/my_file 1 verify(abc) { 2 foo : bar; 3 sub1(aa) { 4 line1; 5 } 6 sub2 (bb) { 7 line1; 8 // this line is a comment ...
2
votes
2answers
77 views

Use sed command for particular lines

I have a text file on a Linux machine and I want to run 3 sed commands for the lines entered by the user using a perl script. I am doing this manually till now. The sed commands I have to use are : ...
0
votes
2answers
61 views

Linux command to delete this

I want to delete this kind a pattern in my text file [-.(D_)-]. I did with sed and awk but no results. basically i want to delete anything that comes between [- & -] along with these characters ...
1
vote
2answers
32 views

Bash Perl multiline match into variable

I am trying to extract 2 strings from a multiline text. postmsg="\033[0;37m Email Settings" This line finds some match at the beginning of the string and puts it in a variable inCol. inCol=$(perl -...
3
votes
3answers
389 views

How can I list the different hex characters between two files?

allHexChars.txt \x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\...
0
votes
2answers
73 views

How to randomly change the order of two columns simultaneously for 1000 times using simulation values?

I have a data looks like this: ID pheno 231 0.12 432 0.32 11 0.0003 134 0.33 2334 0.553 12 0.33 100 0.331 1008 ...
1
vote
2answers
90 views

RegEx for replacing capture group content using sed [closed]

Have inputs.conf files in multiple directories that needs to match and parse each stanza and modify the index= to index=secure. This are files type in inputs.conf and also do run the script to locate ...
0
votes
0answers
20 views

Assign temp file from cgi and read it in .sh [migrated]

I have .cgi file and .sh file. The cgi is calling the script which is the .sh file. How will assign the tempfile created from .cgi and pass it to the .sh file? Example below: (on my CGI, $tmpfile is ...
0
votes
0answers
24 views

Bash-Perl Make Substitution and Return array (string & number of replacements/substitutions)

I have this code that makes substitutions in a file segment. The code should be left mostly unharmed except for this problem. I need to return back to bash, the number of replacements made by perl ...
0
votes
2answers
43 views

Perl Negative Lookbehind with variable length bypass maybe?

I have this simple code perl -we 'my $file= " # parameter=10 # parameter=10 # parameter=10 parameter=10 parameter=10 "; $file=~ s/((?<!# ))\s*parameter\s*=.*/parameter=replaced/g; ...
-2
votes
3answers
50 views

Perl multiline match for 'something' which starts without '#\s'

UPDATE: The REAL answer to this MULTILINE question was given here by Stephane https://unix.stackexchange.com/a/521560/354415 Alternatively go line by line with perl by Terdon below: https://unix....
6
votes
2answers
111 views

number headings

I need to convert whitespace to a tiered, numbered list and have found this elusive. This is the sort of thing I'm after: Input (visible): Project #1 Subproject Task ...
2
votes
1answer
37 views

Perl Script in Bash Here Document (does not output variable)?

How come the following perl code, mkdir("foo"); print "foo: $!\n"; mkdir("foo"); print "foo: $!\n"; Will output the following (in a directory without a foo) perl ./asdf.pl foo: foo: File exists ...
0
votes
0answers
13 views

How to create RPM for generic Perl module

I have a generic Perl module that will run on any release of Perl 5. I need to create an RPM for it that will install it into the vendor_perl subdirectory. I don't want to create different RPMs for ...
0
votes
2answers
52 views

How to remove repetition of the content of file by column?

I have a file containing the following content: WP_021815421.1 OG5_132922 deth|YP_182312 3 -07 42.35 81.7 WP_021815427.1 OG5_128110 rbal|NP_868155 1 -55 50.72 53.2 WP_012456834.1 ...
0
votes
2answers
40 views

compare two column of two different CSV file & merge the output

TABLE1.csv DATE, TIMESTAMP, ID, START TIME, END TIME, DURATION 2019-04-05, 13:57:19, 1607,13:06:42, 13:07:12, 00:00:30 2019-04-05, 13:58:00, 2327,13:57:26, 13:57:43, 00:00:17 2019-04-24, ...
0
votes
1answer
44 views

Calculate the time difference between two columns in time format hh:mm:ss

I want the time difference between column 5 & column 4 My Input: DATE TIMESTAMP ID START TIME END TIME 2019-04-05 13:57:19 1607 13:06:42 13:07:12 2019-04-05 13:58:00 2327 13:57:26 ...
0
votes
0answers
25 views

Why the distr instmodsh cannot list the installed distr/vendor_perl modules ?

We find such a phenomenon with the instmodsh, that is, it can only list the installed CPAN modules ?! So why it cannot list the installed distr/vendor_perl modules though itself belongs to a distr ...
0
votes
2answers
41 views

Why is my multi-line perl string replace adding a blank line?

I'm trying to replace multiple lines in a text file (an XML element with an unknown number of children) with the contents of a separate text file. I've managed to get the replace mostly working using ...
0
votes
5answers
104 views

How can I change the character of a string one by one?

I want to change all the characters in string one by one according to the substitution rule and save them to file on Linux. This is substitution file (sub.txt). A -> Y B -> V C -> Q ... ...
1
vote
2answers
53 views

Howto find the size of a remote http/https directory (non recursively) using a given regexp from the command line

I'm trying to find the size of a remote http/https directory (non recursively) using a given regexp (\.mp4) from the command line, is there a tool to do so or do I need to parse the index.html ? ...
-1
votes
2answers
94 views

How to make code interpret $ but not *? [closed]

I have some perl code (don't focus on what it does right now, i'm still working on it): #!/usr/bin/perl -w if(!@ARGV) { print ("ERROR: NO ARGS\n"); exit 1; } else { use Cwd qw(cwd); my $dir ...
-2
votes
2answers
54 views

How to remove entire array that have specific character

I have a perl code that extract from .xls file. My .xls file is as below NUMBER NAME ALPHABET one Jane a two Adam b three Josh c ;four five Agnes ...
6
votes
8answers
948 views

Delete nth line (when counted from the bottom)

There are unknown number of lines in a file. How to delete nth line (when counted from the bottom) with one-liner command (you may use more than one if it is necessary) on Unix platform.
1
vote
2answers
61 views

fastest way to subsitute on 10GB file for multiple expressions

I have a file of 10GB data, I want to execute 2048 substitution expressions of sed -i 's/pattern/replace_pattern/g' on that file. Is there a way to do it faster and effectively. Currently, I am ...
0
votes
1answer
31 views

Replace middle of filepath while keeping filename at the end?

I am trying to manipulate a file path using bash. The first part of my goal has been completed, where I replace the first half of the file path with the path on my local computer. $> fp=$"/...
0
votes
1answer
40 views

Replace group of similar text in string from nth position with one string else increment the value by +1

I have a text file with following lines for example. Input DD0TRANSID000019021210504250003379433005533665506656000008587201902070168304000.0AK 0000L00000.00 N ...
0
votes
3answers
93 views

Replace text in lines in a file with increments

I have a file with multiple lines (no. of lines unknown) DD0TRANSID000019021210504250003379433005533665506656000008587201902070168304000.0AK 0000L00000.00 N 01683016832019021220190212N0000....
0
votes
0answers
11 views

Log4perl Fails on Linux Lite

I recently re-purposed an old laptop of mine by popping in a new SSD and installing the latest stable version of Linux Lite. I've been trying to get my preferred configuration of Atom running on it. ...
-1
votes
3answers
56 views

how to assign values to intervals with overlapping regions?

I have two big files, the first file contain some intervals with 85K rows: head data.intervals id id_uniq numberA numberB 1 g1 5 20 1 g2 6 29 1 g3 17 35 1 g4 37 46 1 g5 50 63 1 ...
2
votes
1answer
64 views

uniq -c Equivalent for Groups of Lines of Arbitrary Count

I've got a file of ~1-2 million lines that I'm trying to reduce down by counting duplicate groups of lines, preserving order. uniq -c works okay : $ perl -E 'say for (("foo") x 4, ("bar") x 4, "baz"...
0
votes
2answers
262 views

How to install Perl modules on Debian 9?

On a tutorial for installing SendEmail, I found instructions to install 2 prequisites, 2 perl modules apt-get install 'perl(Net::SSLeay)' 'perl(IO::Socket::SSL)' This syntax also resulted strange to ...
0
votes
2answers
45 views

How to append line with strings at the end of variable?

We have the following line in file more file USA_FORMAT="-XX:LOP83746=5M -XX:+YU3635-2837" and we want to append the following strings (line) also at the end of USA_FORMAT variable /usr/jdk64/...
0
votes
3answers
135 views

Replace block of text with sed, awk, perl or vim

I am trying to replace every instance of a block of six rows with another block of six rows, just reducing the six rows block of two columns to a six rows block of only one column. Thank you to your ...
2
votes
0answers
68 views

'Out of Memory' on AIX installing Perl Module [closed]

Getting out of memory error trying to install NetFTPSSL perl module on IBM P750 running AIX 7.1 with 76GB of memory. root@polarprod-cip(/)# perl -MCPAN -d -e 'install Net::FTPSSL' Loading DB ...
0
votes
0answers
74 views

Compare two log files line by line and print difference

I have to compare two different log files line by line (in each line data between two symbols (: and ;) is to be checked) and print all lines of log 1 that are not in log 2. If two or more lines have ...
3
votes
0answers
270 views

perl: warning: Setting locale failed

I bought a VPS, Centos 7. However, I was able to understand what was going on with SSH and connected to my WHM. After connecting, I get a list of errors and there is something like this: perl: ...
5
votes
3answers
511 views

sum all numbers from “du”

We want to calculate the first numbers that we get from du du -b /tmp/* 6 /tmp/216c6f99-6671-4865-b8bc-7205f5388752_resources 668669 /tmp/hadoop7887078727316788325.tmp 6 /tmp/hadoop-hdfs ...
1
vote
1answer
48 views

Unix perl match string and delete line

Im using perl to remove a string from a file, it is removing the string from file, But the actual line is not getting deleted, Due to which the next insert to the files are getting written over next ...
1
vote
3answers
70 views

delete lines matching pattern if it is repeated

Say I have a config file: [main] foo = bar [option] opt1 = opt2 opt3 = opt4 [extra] [footer] [tail] print = true [end] I want to print the headers ([text]) only if there are options underneath. So ...
0
votes
1answer
39 views

Looping 'find…-type f': Getting filenames by dir/subdir, ouputing a txt with name dir_subdir_fname.txt

My data structure is something like: dir1/subdir1_level1/subdir1_level2.../subdir1_leveln dir1/subdir2_level1/subdir2_level2.../subdir2_leveln ... Which means that the levels I'm working with are ...
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 ...