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.

Source: Wikipedia.

Perl is a general-purpose programming language originally developed for text manipulation, but as of 2010 is used for a wide range of tasks including system administration, web development, network programming, games, bioinformatics, and GUI development. The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). Its major features include support for multiple programming paradigms (procedural, object-oriented, and functional styles), reference counting memory management (without a cycle-detecting garbage collector), built-in support for text processing, and a large collection of third-party modules. According to Larry Wall, Perl has two slogans. The first is "There's more than one way to do it", commonly known as TMTOWTDI. The second slogan is "Easy things should be easy and hard things should be possible".

Perl is known as one of "the three Ps" (along with Python and PHP), the most popular dynamic languages for writing Web applications. It is also an integral component of the popular LAMP solution stack for web development. Large projects written in Perl include cPanel, Slash, Bugzilla, RT, TWiki, and Movable Type. Many high-traffic websites use Perl extensively. Examples include Amazon.com, bbc.co.uk, Priceline.com, Craigslist,IMDb, LiveJournal, Slashdot and Ticketmaster. Perl is often used as a glue language, tying together systems and interfaces that were not specifically designed to interoperate, and for "data munging",that is, converting or processing large amounts of data for tasks such as creating reports. In fact, these strengths are intimately linked. The combination makes Perl a popular all-purpose language for system administrators, particularly because short programs can be entered and run on a single command line. More at http://en.wikipedia.org/wiki/Perl

1313 questions
921
votes
10 answers

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 directories? replace only if the file name matches…
terdon
  • 220,769
  • 58
  • 415
  • 622
87
votes
7 answers

How do you list number of lines of every file in a directory in human readable format.

I have a list of directories and subdirectories that contain large csv files. There are about 500 million lines in these files, each is a record. I would like to know How many lines are in each file. How many lines are in directory. How many…
Hexatonic
  • 1,095
  • 2
  • 8
  • 9
53
votes
11 answers

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-file2 "22" line5-file2 "21" After the…
user1228191
  • 771
  • 1
  • 7
  • 10
50
votes
3 answers

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+"$@"} mean? I tried using "$@" instead (using Bash as…
200_success
  • 5,366
  • 1
  • 25
  • 34
47
votes
5 answers

How to "grep" for line length in a given range?

NOTE: This question is the complement of this Q&A: How to "grep" for line length *not* in a given range? I need to get only the lines from a textfile (a wordlist, separated with newline) that has a length range of minimum or equal than 3…
user90825
39
votes
7 answers

Linux equivalent to PowerShell's "one-to-many" remoting

Coming from Windows administration, I want to dig deeper in Linux (Debian). One of my burning questions I could not answer searching the web (didn't find it) is: how can I achieve the so called "one-to-many" remoting like in PowerShell for…
MacMartin
  • 2,432
  • 2
  • 15
  • 21
39
votes
9 answers

How can you combine all lines that end with a backslash character?

Using a common command line tool like sed or awk, is it possible to join all lines that end with a given character, like a backslash? For example, given the file: foo bar \ bash \ baz dude \ happy I would like to get this output: foo bar bash…
Cory Klein
  • 17,221
  • 26
  • 78
  • 92
38
votes
16 answers

Converting CSV to TSV

I have a number of large CSV files and would like them in TSV (tab separated format). The complication is that there are commas in the fields of the CSV file, eg: A,,C,"D,E,F","G",I,"K,L,M",Z Expected output: A C D,E,F G I K,L,M …
user14755
35
votes
2 answers

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 on lines in perl script making it go in 'S' state.
xyz
  • 2,733
  • 9
  • 27
  • 28
32
votes
9 answers

How to delete the last column of a file in Linux

I want to delete the last column of a txt file, while I do not know what the column number is. How could I do this? Example: Input: 1223 1234 1323 ... 2222 123 1233 1234 1233 ... 3444 125 0000 5553 3455 ... 2334 222 And I want my output to be: 1223…
zara
  • 1,293
  • 2
  • 14
  • 22
32
votes
4 answers

Replace multiline string in files

I have a number of files I want to update by replacing one multi-line string with another multi-line string. Something along the lines of: * Some text, * something else * another thing And I want to replace it with: * This is completely *…
ventsyv
  • 939
  • 3
  • 13
  • 21
32
votes
2 answers

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 posted on this site, has security implications. What's the deal?…
Stéphane Chazelas
  • 481,585
  • 88
  • 947
  • 1,398
31
votes
4 answers

Why is Perl installed by default with most Linux distributions?

Why is Perl installed by default with most Linux distributions?
user23312
31
votes
1 answer

What's with all the renames: prename, rename, file-rename?

On my Debian system (well, my LMDE system, but close enough), I have at least 3 different rename programs: /usr/local/bin/rename : This is a Perl script, written by Tom Christiansen. Oddly enough, I can't seem to find which package installed it: $…
terdon
  • 220,769
  • 58
  • 415
  • 622
28
votes
5 answers

How to grep for text in a file and display the paragraph that has the text?

Below is the text in the file: Pseudo name=Apple Code=42B state=fault Pseudo name=Prance Code=43B state=good I need to grep for "42B" and get the output from the above text like: Pseudo name=Apple Code=42B state=fault Does anyone have idea on…
Jaya William
  • 381
  • 2
  • 4
  • 5
1
2 3
87 88