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.

1
vote
2answers
86 views

perl + ignore lines with remarks and delete duplicate lines with match word [closed]

We create the following Perl one liner. In order to delete double lines except the first match line, the second part of the syntax is to ignore the lines with remark "#". Example: # more /tmp/test ...
1
vote
1answer
112 views

Equivalent of “ssh-keyscan -H” in Solaris 10/11

I'm creating a Perl program that adds the specified host in root's known_hosts file. The program works in AIX and Linux, but not in Solaris and sadly, I can't find its equivalent command. Sample line:...
2
votes
3answers
72 views

how to remove syntax with uniq characters from line

we have the following configuration file, env.gc.txt export SERVER_GC_OPTS="-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:{{hbase_log_dir}}/gc.log-`date +'%Y%m%d%H%M'`" We try to ...
3
votes
2answers
88 views

How to add properties in the end of the two first lines with double quote?

We want to add the following properties: -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M in the two first lines that contain the word - HBASE_MASTER_OPTS Example before ...
0
votes
3answers
340 views

Delete the oldest files in folder if combined size of folder is more than 10G

The following syntax will remove the files under hive folder: /usr/bin/find /var/log/hive -type f -print -delete I am trying to do the following: Remove the oldest files under /var/log/hive only if ...
-1
votes
1answer
39 views

How to delete from configuration file variable that not equal to 100

How to delete from configuration file the variable/s hadoop.tasklog.totalLogFileSize that are not equal to 100 example more file.conf hadoop.tasklog.totalLogFileSize=107 hadoop.tasklog....
3
votes
5answers
813 views

Insert multiline text before the first matching line in a file

we want to add the following lines in log4j file log4j.appender.DRFA=org.apache.log4j.RollingFileAppender log4j.appender.DRFA.MaxBackupIndex=100 log4j.appender.DRFA.MaxFileSize=10MB but these lines ...
-1
votes
2answers
72 views

sed + mark line in case of marched word

we want to mark with "#" the matched line by sed or perl line liner for example we want to mark all lines in file that include the DatePattern word log4j.appender.DRFA.DatePattern=.yyyy-MM-dd ...
-1
votes
5answers
265 views

Need a awk/sed to replace the values present inside ${}

I am trying to do url testing by fetching the values from env.properties file. For example, my env.properties will look like this a.host.name=wanx.com b.host.name=xyu.com c.host.name=${b.host.name} ...
2
votes
2answers
65 views

Finding Greek from the command-line

How can I use perl on the command-line to print only lines containing Greek unicode characters? For example, only the second of the following lines hullo, world χαῖρε, ὦ κόσμε It should be ...
1
vote
2answers
64 views

change 3rd character in a line

input: dummy - 22847847 sha - 84734747 DHS - 374874 expected output: du1my - 22847847 sh1 - 84734747 DH1 - 374874
1
vote
3answers
541 views

Delete a part of a line with sed?

I have the next output: Date Time: June 22 12:40:00 Product User Host IP Software User User *.***.***.*** Software1 User User *.***.***.*** I tried some functions with sed and awk, but is not ...
2
votes
1answer
68 views

AWK | Dynamic row to column conversion

My Files: EventTime=20180726001317 ObjectOfReference=TCU_XXX202 SPtext=Heartbeat Failure EAName=TCU_XXX202 EventTime=20180726001317 ObjectOfReference=TCU_XXX203 SPtext=Heartbeat Failure EAName=...
1
vote
2answers
138 views

Getting a row data from matching column in CSV file in Perl?

I am not able to attach the CSV file, so I have attached the images so that the content is clear. I used awk and perl one liners but that is not giving any output. Please help me know, how can I get ...
0
votes
3answers
188 views

Have two lists, want to exclude list2 from list1

List1: 1,name1 2,name2 3,name3 4,name4 5,name5 6,name6 7,name7 ...
1
vote
4answers
66 views

Search and replace using a custom utility

I want to run a utility for replace values matching a regular expression. This means for every match of a regular expression, call the utility with the characters comprising the match. The output of ...
-2
votes
2answers
446 views

how insert column of same number in text file?

I have input file like::: a.txt 1 0.4 0.8 2 0.5 3.0 5 0.8 3.5 I want output like this::: 1.txt 1 3 0.4 0.8 2 3 0.5 3.0 5 3 0.8 3.5 1 8 0.4 0.8 2 8 0.5 3.0 5 8 0.8 3.5 I want to add same number ...
3
votes
1answer
294 views

Remove multiple strings from file on command line, high performance [closed]

Is there an elegant, high-performance one-liner way to remove multiple complete strings from an input? I process large text files, e.g., 1 million lines in inputfile, and 100k matching strings in ...
0
votes
1answer
63 views

grep + search recursive complex syntax under folder in files/scripts

We want to search the following line recursive under folder/s awk '{print}'|grep -i -e 'port is up' -e 'valid output' so we did that: grep -r "awk '{print}'|grep -i -e 'port is up' -e 'valid output'...
-2
votes
1answer
50 views

replace name after specific syntax

We have Bash script. We want to change the name - master02 with $machine_master in the Bash script. value=master02_up #master02 http://master02.$domain:8080 How to change master02 to $...
0
votes
1answer
115 views

Why doesn't rpm or dnf recognize default perl?

I have an rpm package I built which depends on perl. When I try to install this package it fails: $ rpm -ivh <package-y> error: Failed dependencies: perl is needed by package-y.x86_64 If I ...
0
votes
3answers
889 views

How to remove control Z characters from a file?

File has control Z( ^Z) characters in them. I tried sed 's/^Z//g' file_name but not working. Even tried perl script but not removing them. Please let me know if there is way to remove this character.
0
votes
2answers
128 views

Compare one column from one file with all columns in another file

I have two files. File 1 has a pattern in the form of a single column that I want to compare with all columns in file 2 to ultimately count how many columns in file 2 show that pattern. The number of ...
2
votes
1answer
190 views

listing files of a specific date and writing to another file in perl

I have a list of .DTA files with below dates. Jun 26 02:53 fs261803.DTA Jun 26 02:54 fs261804.DTA Jun 26 02:56 fs261805.DTA Jun 26 03:25 fs261865.DTA Jun 26 03:27 fs261869.DTA Jun 27 03:21 fs271865....
4
votes
3answers
500 views

Get time difference of two dates using awk

I have a file of size 7GB. Now have two date time in that I want to use awk to get this difference of time between that two DateTime. Below is how my files look like: A B C D ...
1
vote
2answers
343 views

Change the background color (html format) if a number is less than a threshold

I have the folowing file which is called test.html: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <meta name="generator" content="SQL*Plus ...
5
votes
2answers
450 views

Could someone explain this shebang line which uses sh and then does exec perl?

This is from Programming Perl, Fourth Edition. It's about executing a Perl script. Finally, if you are unfortunate enough to be on an ancient Unix system that doesn’t support the magic #! line, ...
0
votes
2answers
89 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 ...
-2
votes
1answer
68 views

how to very exact match on complex lines

we have the following file: more test.txt export KAFKA_HEAP_OPTS="-Xmx8g -Xms8g" export KAFKA_JVM_PERFORMANCE_OPTS="-XX:MetaspaceSize=96m -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:...
1
vote
1answer
436 views

Perl Issue on OS X El Capitan

For some strange reason, OS X suddenly shows me: Can't locate strict.pm: Permission denied at /usr/bin/shasum5.18 line 100. BEGIN failed--compilation aborted at /usr/bin/shasum5.18 line 100. when ...
2
votes
1answer
99 views

awk paragraph does not work

I have downloaded the KingBase Lite 2018 Update 3 file from here. I now want to extract data from a single event such as the "FIDE Candidates 2018": I want to get all the paragraphs containing this ...
2
votes
1answer
377 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
290 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
130 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
1k 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
94 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
70 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
58 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
68 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
112 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
82 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
228 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
71 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 ...