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
2
votes
1answer
401 views

jq + print properties from json file without removing the necessary backslash

we have the following json file: more file.json { "href" : "http://master02:8080/api/v1/clusters/HDP/configurations?type=kafka-env&tag=version1527250007610", "items" : [ { "href" : ...
8
votes
3answers
2k views

How can I remove the last comma separator from the end of a file?

How can remove the last comma separator from a file on Linux? Example of file : "is_supported_kafka_ranger" : "true", "kafka_log_dir" : "/var/log/kafka", "kafka_pid_dir" : "/var/run/kafka", "...
1
vote
1answer
310 views

I can't find module “core” in perl dir on ubuntu 18.x

I'm trying compile nginx ... configure seems ok, then when I type make I get following error: make make -f objs/Makefile make[1]: Entering directory '/home/paul/src/ngxbuild/nginx-1.14.0' cc -o objs/...
1
vote
1answer
159 views

How to insert file content after a certain string in a file? [duplicate]

we have for example this file cat exam.txt I am expert linux man what we can do for out country I love redhat machine "propertie" centos less then redhat fedore what my name is moon yea we want to ...
10
votes
5answers
2k views

awk/sed/perl one liner + how to print only the properties lines from json file

how to print only the properties lines from json file example of json file { "href" : "http://master02:8080/api/v1/clusters/HDP/configurations?type=kafka-env&tag=version1527250007610", "...
0
votes
6answers
1k views

awk/sed/perl one liner to edit json file

We want to add the folwing lines: export KAFKA_HEAP_OPTS="-Xmx8g -Xms8g" and: export KAFKA_JVM_PERFORMANCE_OPTS=" -XX:MetaspaceSize=96m -XX:+UseG1GC-XX:MaxGCPauseMillis=20 - XX:...
2
votes
1answer
1k views

Strings replace in bash using multiple lines pattern

How can I do a string replace in bash using multiple lines pattern? To illustrate I present a pseudocode: TARGET_STR=' $N = "magic_quotes_gpc = <b>"._("On")."</b>"; $D = _("...
1
vote
5answers
2k views

Replace spaces with underscores only when within quotes

I need to replace all spaces which exist within quotes. I have several columns yet only one column has quoted output containing spaces which is throwing off my columns when using column -t "UDP ...
0
votes
1answer
60 views

how to add string if word ended with specific string

we want to update the following file , in case MACHINE_NAME ended with ".localdomain" then need to add the string linux in the beginning of the word each MACHINE_NAME comes with single brackets '.......
0
votes
4answers
95 views

Modification required for the perl command

I need a modification for the below perl command: perl -wE 'say for ((sort { -s $b <=> -s $a } </tmp/?>)[0..9]);' Requirement: It should scan through all the sub-directories inside the ...
0
votes
1answer
75 views

Collapse rows based on a key in a csv file using awk or perl

Input csv file : key,c1,c2,c3......,cn 1,car,phone,cat,.....,kite 2,abc,def,hij,.......,pot 1,yes,no,is,.........,hello 2,hello,yes,no,......,help Output csv file: Key,c1,c2,c3,.......,cn 1,caryes,...
0
votes
2answers
59 views

Printing out users without /home directories and /home directories without users

I need to develop a perl script that will generate a formatted listing of any user without a home directory and any home directory that is not attached to a user. For example, if I used the script ...
0
votes
1answer
71 views

Replace the string as $test

I am having many text file with different directories. I need to search one specific string and I need to replace the string with the specific value as $test. I need to search the all files in all ...
5
votes
2answers
107 views

sed regexp text processing capture grouping referencing alternation confusion

sed's capture grouping ALTERNATION is not working as expected. While alternation has the lowest precedence, here is the confusion: echo "abcd_aefghi" | sed -r "s/(a)(b)(c)(d)|(a)(e)(f)(g)/\8/g;" ...
4
votes
4answers
114 views

Replace pattern each time with a different string (taken from external file)

I have an input: a b TOCHANGE c d e TOCHANGE where I need to change the patterns "TOCHANGE" using an external file : line1 line2 ... so that I get the following output : a b line1 c d e ...
0
votes
1answer
87 views

Regexp: Horribly slow regexp in perl - how to optimize?

This: echo BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BA BBBBBBBBBBBBBBBBBBBBBBBBBBBBA | perl -pe '/^(.*?B(?:A.*?B){30})A/' takes an astonishing 8 seconds on my machine. I had ...
0
votes
2answers
263 views

Controlling curl output on Debian

I'd like to run a curl command and only have content written to stdout if there is an error. When I run the command from the terminal I get this functionality by default. When I run the command from ...
3
votes
1answer
2k views

Opposite of \K, to keep the stuff right [duplicate]

On the perlre's extended patterns page we can read about \K: Keep the stuff left of the \K, don't include it in $& Here is the practical example using GNU grep (which actually keeps stuff ...
0
votes
2answers
76 views

Delete text between parentheses, but never past empty line

Consider a text file, with lines of text gathered in many blocks, where each block is separated by at least one empty line. Using a Bash one-liner, how do I delete all text from < to either > or ...
1
vote
1answer
635 views

How to remove newline character within a column in a tsv file?

I need "This contains newline" in one row, newline from the column2 and column4 need to remove. nb: For your understanding the data I upload an image if you want I will upload the text content "...
0
votes
1answer
91 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
2answers
126 views

Regex Pattern and Replace line with substitution

For a migration process, I need to do some replacement in my bash script. So in my .txt files, I have these references for example: [[File:My Image.png|400px|thumb|center|My Image]] [[File:My Image....
6
votes
3answers
1k views

Replace UTF-8 characters with shell perl

How do I get perl to properly replace UTF-8 character from a shell? The examples use stdin, but I need something that works for perl ... file too. This is what I expect: $ echo ABCæøåDEF | perl -CS ...
0
votes
2answers
590 views

Fixing malformed CSV with incorrect new line chars using sed or perl only

I have a comma-delimited CSV file but for some reason our system inserts a new line character at a random location in the file which causes the entire file to break. I can get the number of columns in ...
1
vote
2answers
45 views

Concating fields and removing trailing whitespace in one line

I have a string with 3 fields separated by whitespace. I would like to concat the 2 last fields with - making sure that the newline in the end is removed. The following works: echo -n "abc 1234 ...
0
votes
1answer
599 views

Replacing getopts.pl with Getopt::Std [closed]

I am using Cygwin version 2.10.0 with perl 5.26.0. I need to change getopts.pl to Getopt::Std but what to do with &Getopts('F:f:'); line then? #! /usr/bin/perl require "getopts.pl" ; # Perl ...
1
vote
3answers
344 views

remove duplicated pattern/entries within each field in CSV file

How do I remove duplicated entries within each separate fields with below sample as data. 0x,9.4,,,#0,#UNIX#unix,#cli#L#فا#0#فا#0#L#SE#Cli#SE,#فارسی#فارسی#۱#1#١#1,bsh,#V & v expected output(...
2
votes
2answers
3k views

delete files older than X minutes

I want to move files and Directories older than 15 min of creation to archive folder in HP Unix but i did not find any option for it. I created a Perl script for it but it is moving files only not ...
0
votes
2answers
191 views

Parse a log using perl

Im looking to parse a log using a perl command that I designed. So far all I would like to accomplish is pulling a specific timestamp format and retrieve the host. the log would look like this 2016-...
0
votes
1answer
34 views

how to verify at least XG free space on /var

we have the following df -h output [root@trump var]# df -h | grep "/var" /dev/mapper/vg-lvm_var 101G 85G 17G 84% /var how to verify at least 10G free space on /var in bash/awk/perl one liner ...
1
vote
1answer
69 views

I can't print the default text in the Readline input

I am writing an interface to my database and would like to be able to edit entries. I thought I'd use Readline, but can't get it work. I'd say my code should work, based on Term::ReadLine::Gnu and ...
2
votes
2answers
92 views

Merge lists based upon duplicate values

I have sorted data like this: a a f b c c e d f z Essentially these lines are each lists of aliases for the same thing, and they need to be merged. This is simplified. In case it matters in the real ...
1
vote
2answers
196 views

sync password hashes of users UID>1000 between host A and B

I have two CentOS systems, I want to do syncing of password hashes (only) which are stored in /etc/shadow, from system A (local) to system B (remote) but only for these users which have UID > 1000 and ...
0
votes
3answers
587 views

perl oneliner - random string generator with non-alphanumeric [closed]

how to add non-alphanumeric characters to the map so it generates mix of alphanumeric and non-alphanumeric characters? $ for i in {1..5};do perl -le 'print map { (a..z,A..Z,0..9)[rand 62] } 0..pop' ...
0
votes
2answers
193 views

Match the nearest timestamp in milliseconds

I have a large data.txt file as below; for every timestamp, I need to find the nearest time match 5 minutes later and the value on column 4. Now print both in two new columns. for example for "2018-...
1
vote
2answers
54 views

Matching a pattern in Perl

I have a below input file which contains: 000ABCDEFGHIJKLMN2018022623595900021 CGT11~|~|110~|~|221~|~|H0331~|~|~|~| CGT11~|~|110~|~|222~|~|H0332~|~|~|~| CGT11~|~|110~|~|223~|~|H0335~|~|~|~| CGT11~|~|...
1
vote
1answer
631 views

Script cannot find Perl module, but module exists in local subdirectory

I'm running a Rasbian strecth 4.9.59-v7+ and I´m trying to run the following software https://github.com/weaknetlabs/warcarrier which looks really neat! When trying to run the script I receive the ...
0
votes
2answers
82 views

Remove lines of a file after the N firsts lines but before to integer number

I have a file like this: 1 2 3 4 5 0.05775 0.00238 0.02514 0.00469 0.01882 0.26868 0.04114 0.09359 0.02155 0.01367 0.11413 0.00907 0.04032 0.02487 ...
0
votes
3answers
108 views

what is the best way to match a version number from file

what is the best way to match specific version number ( or version number ) from file I did some options , but I think there are other best approach ( as perl one-liner ) version=23.092.12 cat ...
0
votes
1answer
179 views

log file check validation in Perl

I have "FDP_RecordLength_Error_02202018_020107.log" "FDP_HeaderOrTrailerRecord_Error_02202018_020107.log" "FDP_DetailRecord_Error_02202018_020107.log" and other log files as well. I want to check the ...
1
vote
1answer
33 views

Transposing Data - Easier Way to Add Additional Columns to Perl Script

I have a perl scrip below that does a fantastic job, however, I how want to perform the same task but on a larger file. The script below is designed for use on a file containing 15 columns, of which ...
0
votes
1answer
189 views

Cannot install URI::_foreign

Well I'm trying to install URI::_foreign on my server (I have root access) I get the following errors: CPAN: Storable loaded ok (v2.20) Going to read '/root/.cpan/Metadata' Database was generated on ...
-1
votes
3answers
120 views

awk perl copy first column in new lines

i use bash i have table like this 001_1_174 [g/n 474536 482492 mo[g/n 482492 504062 'er/ 504062 ...
4
votes
5answers
958 views

‌How to select rows with minimum value in each group based on first column as ID?

I have a file looks like this : 1 7.8e-12 1 7.8e-12 1 1.0e-11 2 9.3e-13 2 3.5e-12 2 3.5e-10 2 3.1e-9 3 3.0e-11 3 3.0e-11 3 1.7e-08 For every ...
2
votes
1answer
420 views

Log rotate using perl Logfile::Rotate

The below script works when executed on CentOS, but it doesn't rotate logs based on size. A new log is generated every time I execute this script. Can anyone tell me how to make this script work based ...
0
votes
1answer
40 views

How to remove a place holder in a text file with text from another file when multiple lines are present?

I have a file: - id: 1.4.25.2 name: 'Configuring a VNC Server' permalink: '/rhcsa/managing-network-services/configuring-vnc-access/configuring-a-vnc-server' description: '<*...
3
votes
3answers
2k views

What does '(…)? = $1 : $2' do in Perl?

I came across with these two lines, and though I've been trying to figure out what they do, I'm still in doubt about their meaning in the code. The piece of code I am talking about is: my $...
0
votes
3answers
93 views

AWK: search last column of INPUT.txt in TABLEs text and add correspond columns to INPUT.txt

dear all i have INPUT.txt like this (look at last column) INPUT.txt 63 M 27 BS/BA TEHRANI 3 4 298320 310050 11730 j j 63 M 27 BS/BA TEHRANI 3 4 310050 311430 1380 ( a 63 M 27 BS/BA TEHRANI 3 4 311430 ...
0
votes
0answers
145 views

zabbix template mysql (800+item)

I use this template. template-mysql-800-items when i send parameter by this command zabbix_sender -z zabbix -s db1 -k mysql[innodb_queries_inside] -o 100 -vv On zabbix server i can see result. ...
1
vote
1answer
89 views

Perl podusage generates man page with extra control-O's

I am using pod2usage in a Perl script to generate a man page. The code looks like this: use Pod::Usage; pod2usage(-verbose => 2) ; exit 0 ; ... some code ... __END__ ...