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 ...

learn more… | top users | synonyms

30
votes
1answer
35k views

How can I replace a string in a file(s)?

Replacing strings in files based on certain search criteria is a very common task. How can I replace string foo with bar in all files in the current directory? do the same recursively for sub ...
17
votes
2answers
10k views

What does ${1+“$@”} mean in a shell script, and how does it differ from “$@”?

In the Perl documentation, perlrun(1) suggests launching Perl scripts using a bilingual shell/Perl header: #!/bin/sh #! -*-perl-*- eval 'exec perl -x -wS $0 ${1+"$@"}' if 0; What does ${1+"$@"} ...
12
votes
2answers
203 views

Security implications of running perl -ne '…' *

Apparently, running: perl -n -e 'some perl code' * Or find . ... -exec perl -n -e '...' {} + (same with -p instead of -n) Or perl -e 'some code using <>' * often found in one-liners ...
10
votes
6answers
401 views

Using Perl to count the number of scientific numbers in a file

How I can count the number of scientific numbers in a file? The file also has a few lines of header which needs to be skipped. A portion of the file's content is in below. FileHeaderLine1 ...
10
votes
4answers
2k views

Why is Perl installed by default with most Linux distributions?

Just curious. The title says it all: Why is Perl installed by default with most Linux distributions?
10
votes
2answers
6k views

How to know reason of a process going to sleep state and wake it up?

When I do 'top' , I see my perl script process in 'S' state. Is there a way to know, what is making this perl process go in sleep state and ways to wake it up? Any way to debug to give more insights ...
10
votes
2answers
116 views

Resource friendly way to indicate to user program is not hanging

I have a Perl script on a *nix system which, at one point, is processing 50,000 + lines of text. This takes some time. I am trying to find a resource friendly way to let the user know the program is ...
8
votes
6answers
2k views

Delete lines beginning with #

How do I delete lines beginning with a #, given that there can be whitespace on the left and right of the #? # Master socket provides access to userdb information. It's typically
8
votes
1answer
381 views

Is there a way to make perl -i not clobber symlinks?

A friend of mine points out that if you do: perl -pi.bak -e 's/foo/bar/' somefile when "somefile" is actually a symlink, perl does just what the docs say it will do: It does this by renaming ...
7
votes
6answers
2k views

Is there any alternative to grep's -A -B -C switches (to print few lines before and after )?

grep -A 2 -B 3 prints 2 lines after the grep string and prints 3 lines before. grep -C 3 prints 3 Lines before and 3 lines after Unfortunately, the grep I'm using does not support these ...
7
votes
4answers
2k views

Find files with same name but different content?

I want to generate a list of files that have: Same name Different content in a directory (including all children directories and content). How to do? Bash, perl, anything is fine. So, two ...
7
votes
5answers
11k views

invalid SSL_version specified at /usr/share/perl5/IO/Socket/SSL.pm line 332

Since I upgraded my PC from (k)ubuntu 12.04 to 12.10 I receive this error message when trying to send an email using sendemail. Installing an older version of IO::Socket::SSL is not an option. I ...
6
votes
4answers
4k views

How to remove multiple blank lines from a file?

I have some text-files I use to take notes in - just plain text, usually just using cat >> file. Occasionally I use a blank line or two (just return - the new-line character) to specify a new ...
6
votes
3answers
547 views

Is there a perl or awk solution for this problem?

I have an input file (input.txt) like below. id1 id2 name weight 53723848 12651711 timburnes 1.36667 53530214 12651711 timburnes 1.51191 53723848 53530214 timburnes 1.94 764157 ...
6
votes
2answers
168 views

Sorting with Perl respecting Locale Settings

Following data needs to be sorted respecting the locale sort order: wird sin wär pêche war Über Uber péché peach There was nor problem by using sort $ sort < data peach pêche péché sin Uber ...
6
votes
2answers
3k views

Replacing missing value blank space with zero

I have input.txt tab-delimited text file around 30K lines, I would like to check each row (s1..s30K lines) for missing value (i.e blank space) and fill the missing value with zero value.See out.txt ...
6
votes
3answers
7k views

How can I install perldoc on Ubuntu?

Ubuntu 10.10 comes with Perl 5.10.1 pre-installed, but strangely enough perldoc isn't part of the package. $ perldoc You need to install the perl-doc package to use this program. How can I make ...
6
votes
1answer
4k views

Execute Nohup command with input

In UNIX, I have a process that I want to run using nohup. However this process will at some point wait at a prompt where I have to enter yes or no for it to continue. So far, in UNIX I have been doing ...
6
votes
2answers
672 views

Special character '#' in Perl SSH command

I try to send command using SSH in my perl script with # but it gets truncated right at # Example: Input text is : $message = "Product ID # STK000134" The SSH command is : $execute=`ssh -q ...
6
votes
2answers
414 views

Using empty line as context “group-separator” for grep

I need grep output with context, in color, and blank lines as group separator. In this question, I learned how to define custom group-separator, and I have constructed my grep command like this: grep ...
6
votes
3answers
434 views

What is the difference between invoking a perl script via sh or perl

I have a simple Hello World perl script. #!/usr/bin/perl print 'Hello world.'; It works fine if I run it via perl <file_name>, but it fails I run it via sh <file_name>. My ...
6
votes
2answers
2k views

Remove unknown unicode character from textfiles - sed, other bash/shell methods

I need to search and replace all occurences of an unknown character in some files having the same name. Opening such files with vi, I read <91> code for that character. Opening them with nano, I ...
5
votes
2answers
298 views

How is the inplace modification of a file being done?

What does the "inplace" modification of a file e.g. via sed -i or perl -i mean? My question is about how this inplace modification is done. Is the file copied the modification is done in the copy and ...
5
votes
2answers
151 views

run perl script with unknown perl location

I'm developing a perl script which expected to be downloaded by Mac users with a very small knowledge of shell, linux etc, let's say office managers and accountants. After the downloading the script ...
5
votes
1answer
2k views

Replacing multiple lines in sed or awk [closed]

I'm trying to use sed or awk to replace 5 lines in a smb file but I just don't have any idea how to deal with the newlines.
5
votes
2answers
790 views

Installing CPAN dists not in the Arch repos

There's a lot of CPAN distributions in the Arch repositories, but not all of them. How should I handle a situation when I need a dist that is not already in the repos? Should I use the cpan program ...
5
votes
1answer
239 views

Execute a command within 'sed'

I have a list of random memory addresses saved in a text file, and I need to sed them out, decode them, and save them back to my file. However, the decoding operation I'm trying to perform is handled ...
5
votes
2answers
282 views

Trying to do arithmetic in Perl rename tool (Debian)

Supposed I have five mp3 files: 01-trackfoo.mp3 02-trackbar.mp3 03-trackbaz.mp3 04-trackabc.mp3 05-trackxyz.mp3 Now I give a quick listen to the files (just mplayer on console will do the trick) ...
5
votes
3answers
2k views

Regex & Sed/Perl: Match word that ISN'T preceded by another word

I'd like to use sed or perl to replace all occurrences of a word that doesn't have a certain word in front of it. For example, I have a text file that contains a plot of a movie and I want to replace ...
5
votes
1answer
936 views

Using Modifiers of Perl-compatible Regex (PCRE) in grep

According to grep --help and man grep, we can use the -P option in order to interpret the pattern as a Perl regular expression (PCRE, to be precise), instead of the default POSIX basic regular ...
5
votes
1answer
1k views

Renaming files to have lower case extensions with 'rename'

I'm trying to currently rename a large set of files and have been using quite kludgy methods to do so, such as: rename 's:(.*)\.MOV:$1.mov:g' *.MOV rename 's:(.*)\.JPG:$1.jpg:g' *.JPG What I'd ...
5
votes
2answers
243 views

Getting or cloning the users current terminal?

I have to work with a script that forks and launches an instance of xterm in order to display log output in one window and have an interactive interface in the other. Personally I prefer rxvt-unicode ...
5
votes
3answers
3k views

How to filter IPv4 and IPv6 addresses?

echo "1.1.1.1" | awk '/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/ {print $1}' How can I filter IPv4 addresses in a script, and how can I filter IPv6 addresses. I mean more precisely then this so the oneliner ...
5
votes
1answer
274 views

Passing clicked links in rxvt to a script

I start my browser vimprobable in tabbed like so: "`tabbed -d > /tmp/tabbed.xid`; vimprobable2 -e `cat /tmp/tabbed.xid`" [1] I am then able to send all new instances of vimprobable to tabbed (and ...
5
votes
1answer
49 views

Count duplicate rows with constraint

I have the following file: A B 1990 A C 2001 A C 2013 A B 2001 B C 2013 A D 2001 A D 2014 I need to count duplicate pairs (in the 1st and 2nd column) and to each such pair assign the lowest value ...
4
votes
7answers
338 views

How can I groups numbers in a file

I have a file with numbers in float format. I can review them via sort -rn numbers.txt | less I would like though to be able to "group" them. I.e. easily see how many are in the same range. To give an ...
4
votes
5answers
8k views

extract the 4th column from a csv file using unix command

I have a csv file formatted as below. "col1","col2","col3","col4" "1","text1","<p>big html text</p> ","4th column" "2","text2","<p>big2 html2 text2</p> ...
4
votes
2answers
1k views

How do you determine if AIX 5.3 has perl installed?

Simply put, how do you determine if AIX 5.3 has perl installed as non-root?
4
votes
6answers
103 views

Only show the lines that are in all textfiles at least once

a.txt cat a.txt a b x c b.txt cat b.txt d e a f the q: SOMEMAGICK *.txt a Q: how can I show only the lines that are in all *.txt files?
4
votes
2answers
7k views

Compare two file columns

I have long text files with space-delimited fields: cat file1.txt Id leng sal mon 25671 34343 56565 5565 44888 56565 45554 6868 23343 23423 26226 6224 77765 88688 87464 6848 66776 23343 63463 ...
4
votes
4answers
236 views

Howto find and move a text line inside a file?

I need to change a text line position inside a file; from one line position to another one, underneath a defined text. For example, I have the following text block (on /etc/pam.d/system-auth file) ...
4
votes
4answers
188 views

How to switch the first letters of two words?

$ echo 'foo bar' | sed SOMEMAGIC boo far $ echo 'one two' | sed SOMEMAGIC tne owo Q: in general, how can I replace the "b" from the "bar" to the "f" of the "foo"? And in reverse too, replace the "f" ...
4
votes
2answers
890 views

Replace string with sequential index

Can someone suggest an elegant way to accomplish this? Input: test instant () test instant () ... test instant () //total 1000 lines output should be: test instant1 () test ...
4
votes
2answers
153 views

Column mismatch and substituting

input.txt (tab-delimted) TTTTOTTT00000000008 RTTTT899 5.00E-28 TTTTOTTT00000000046 RTTTWRR 3.00E-31 TTTTOTTT00000000051 2.00E-11 TTTTOTTT00000000051 7.00E-12 TTTTOTTT00000000054 ...
4
votes
4answers
1k views

How can I remove a specific string from a file only if there are other lines in the file?

How can I remove a specific string from a file ONLY if there are other lines in the file? For example, don't touch this file: cat file.txt ASDF but remove "ASDF" from this file: cat file.txt ASDF ...
4
votes
2answers
79 views

Get the maximum sum for a file on 2 keys

I have a file as below. key1 key2 key3 a1 2 l1 a1 2.5 l2 a2 2 l2 a3 2.5 l3 a3 2.1 l4 a3 2.2 l5 I am trying to find the maximum possible sum of key2 that satisfies the ...
4
votes
3answers
3k views

Help with 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 ...
4
votes
2answers
68 views

Using perl to modify a LaTeX document

I am trying to use perl in order to modify a LaTeX document. In fact, I am trying to change the citation format from for example: . \cite{poelma20113d} to \cite{poelma20113d}. In other words, I ...
4
votes
1answer
79 views

Regex this question format into LaTeX

1. Lorem ipsun la la la? 1. Sopor 2. Stupor 3. Torpor 2. A patient has Lorem? 1. Sopor 2. Stupor 3. Somnolentia 4. La 5. Coma 3. Doesn't Response to strong external irritants is short. Tendon, ...
4
votes
6answers
383 views

What is the easiest way to check if column A and B values goes both ways with AWK? [closed]

What is the easiest way to check if column A and B values goes both ways? Output to check: Mike John John Mike Pamela Barbara Barbara Pamela Mike Paul Roger Paul Desired output Mike <-> ...