Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
2answers
25 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
19 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
73 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*//...
1
vote
2answers
64 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
73 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
90 views

How can I set up a local MTA on NixOS?

caff from nixpkgs.pgp-tools seems to require a local MTA to send keys with UIDs signed to the corresponding email addresses. (It uses perl's Mail::Mailer for that.) How can I set up a local MTA on my ...
0
votes
1answer
35 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
30 views

Using Grep in perl script [on hold]

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 ...
0
votes
2answers
58 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 ...
3
votes
3answers
384 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\...
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 -...
0
votes
2answers
68 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
88 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
3answers
134 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 ...
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
1answer
2k views

How to submit multiple commands as one liner in netbatch nbq commmand line

Can someone tell how to submit a one liner command using nbq command line? Submitted multiple commands in Linux works fine but not in nbq mode as below. find /nfs/disks/test_dir/ -name .snapshot -...
0
votes
0answers
23 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 ...
-2
votes
3answers
48 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....
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; ...
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 ...
30
votes
10answers
54k views

How to insert the content of a file into another file before a pattern (marker)?

File1 contents: line1-file1 "1" line2-file1 "2" line3-file1 "3" line4-file1 "4" File2 contents: line1-file2 "25" line2-file2 "24" Pointer-file2 "23" line4-...
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 ...
8
votes
5answers
56k views

How to convert from one date format to other format?

I have one problem with my date format. I want to change from one format to the other and vice versa. My date formats are Format 1 YYYY-MM-DD Format 2 MM/DD/YYYY I want to change format 1 to ...
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 ...
2
votes
2answers
72 views

Perl regex to recognize multiple strings

I have a file ~/foo.txt that has instances of each of the following strings alpha-1 alpha-2 alpha-3 alpha-4 alpha-5 alpha-6 alpha-7 alpha-8 alpha-9 I would like to replace each of these alpha-X with ...
0
votes
2answers
40 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
1answer
89 views

Perl: replacing commas between quotes with @ symbol

I have this tricky text block where some ending quotes appear on the next line. I want to replace every comma appearing between quotes with @ symbol. "----, ----",, ----, ----,,"",start quote," ...
0
votes
1answer
907 views

how to print only Difference in two files using NR=FNR?

we have to print the old entries only Delta(Difference) in File-1 and File-2. newly added enties in files-1 no need to print. on my unix server everyday new report is extracted from system which is ...
3
votes
2answers
2k views

No idea how to troubleshoot Bugzilla email issue

I have a Bugzilla 4.2.4 install that is now unable to send email. It was able to send email without issue up until about a month ago (after about three months without issue). If someone posts a ...
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
24 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 ...
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 ...
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 ... ...
-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 ...
14
votes
7answers
42k views

Repeat each line multiple times

Would like to have each line in a file repeated a fixed number of times. e.g. have each line repeated four times: a b c becomes: a a a a b b b b c c c c I've done some searching, and there are a ...
5
votes
3answers
7k views

piped program in sendmail's /etc/aliases

I'm trying some sort of auto-subscription via a homegrown script. I know it can be achieved by mailing lists such as Mailman but I also want to learn at the same time on how to do it by hand. Here's ...
6
votes
8answers
945 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
60 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 ...
-1
votes
3answers
3k views

Find files less than 1 week old with match TODO in files

My unsuccessful proposal find ./ -newerct '1 week ago' -print | grep TODO No output although should be. Files are text files like Lorem % TODO check this out Lorem ipsun How can you find less ...
1
vote
2answers
2k views

Parse XML file to copy the content into another file at a particular spot in the file?

I have an xml file (client_23.xml) in which I need to add few lines at a particular section basis on what is there in other xml file (abc_lop.xml). Here is my abc_lop.xml file in which you see I have ...
0
votes
3answers
208 views

Grep end regex matching

On OS X, system_profiler SPHardwareDataType outputs: Hardware Overview: Model Name: MacBook Pro Total Number of Cores: 4 L2 Cache (per Core): 256 KB L3 Cache: 8 MB Memory: 8 GB I want to ...
1
vote
4answers
1k views

Change specific part of file via a shell script

What is the simplest way to search for a word in a file given in the command line, with this format ./<file1> -f <file2> --edit <id> <column> <value> I want to search a ...
2
votes
3answers
2k views

Failed dependencies trying to install package 'libxml2'

I am trying to install libxml2, but my system complains about dependencies. The dependent packages exist on system. The ultimate goal is to install xml_grep2, I have been trying various methods (cpan,...
2
votes
2answers
527 views

How do I install the Perl module File::HomeDir on Arch Linux?

I need to install the Perl module File::HomeDir on a laptop running Arch Linux. In order to find out which (pacman-)package contains that module, I run pkgfile -u pkgfile HomeDir.pm The second ...
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
39 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
91 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....