Skip to main content

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.

965 votes
10 answers
1.8m 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 ...
terdon's user avatar
  • 245k
105 votes
8 answers
227k views

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 ...
Hexatonic's user avatar
  • 1,295
61 votes
11 answers
114k 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-...
user1228191's user avatar
55 votes
5 answers
97k views

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)...
user avatar
53 votes
3 answers
41k 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+"$@"} ...
200_success's user avatar
  • 5,585
41 votes
9 answers
28k views

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 ...
Cory Klein's user avatar
39 votes
17 answers
37k views

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 ...
user avatar
39 votes
7 answers
6k views

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-...
MacMartin's user avatar
  • 2,964
37 votes
2 answers
68k 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 ...
xyz's user avatar
  • 3,011
37 votes
4 answers
58k views

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 ...
ventsyv's user avatar
  • 1,039
36 votes
9 answers
84k views

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 ...
zara's user avatar
  • 1,333
33 votes
2 answers
3k 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 ...
Stéphane Chazelas's user avatar
33 votes
1 answer
4k views

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 ...
terdon's user avatar
  • 245k
32 votes
5 answers
56k views

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=...
Jaya William's user avatar
32 votes
4 answers
13k views

Why is Perl installed by default with most Linux distributions?

Why is Perl installed by default with most Linux distributions?
user avatar

15 30 50 per page
1
2 3 4 5
91