Perl is a powerful, high level programming language. Questions about Perl should be limited to the Perl development environment, running Perl, or using Perl to automate tasks on your computer.
Questions tagged [perl]
505 questions
209
votes
18 answers
Removing ANSI color codes from text stream
Examining the output from
perl -e 'use Term::ANSIColor; print color "white"; print "ABC\n"; print color "reset";'
in a text editor (e.g., vi) shows the following:
^[[37mABC
^[[0m
How would one remove the ANSI color codes from the output file? I…
user001
- 3,994
85
votes
11 answers
When to use Bash and when to use Perl/Python/Ruby?
We are doing all our scripting with Bash so far, but I'm starting to feel a bit silly about it. While we can of course do everything we want with Bash (it's quite powerful), I'm starting to wonder if we shouldn't use a proper scripting language (in…
futlib
- 1,289
38
votes
5 answers
How to cut a file to a given size under Linux?
I want to shrink a file's size by brute-force, that is, I don't care about the rest, I just want to cut the file, say by half, and discard the rest.
The first thing that comes to mind is Perl's truncate. I'm following the example on that page and…
xpt
- 9,385
- 44
- 120
- 178
34
votes
12 answers
How do I remove a file in Linux whose name looks like it's ONLY a hyphen, as in "-"
I've tried
rm -- -
rm "-"
rm "\-"
rm \-
Gave Perl a shot
~$ perl -e '$junk = glob("-"); chomp $junk; print "$junk\n"; `rm $junk`;'
-
rm: cannot remove `-': No such file or directory
...and...
~$ perl -e '$junk = glob("-"); chomp $junk; print…
jgrundstad
- 353
29
votes
5 answers
Can I use perl regular expressions in the vim command line?
I want to use perl regular expressions on the vim command line. For example, to capitalize the words on the current line, you could type:
:s/(\w+)/\u$1/g
user51549
- 391
23
votes
3 answers
Command vs program?
I was looking up the difference between adduser and useradd, and an explanation is that useradd is a command while adduser is a perl script. I understand what a perl script is, but what I do not understand is what a command then exactly is.
I always…
kramer65
- 1,442
- 4
- 26
- 43
20
votes
8 answers
How do I queue multiple files for copying on a Mac?
When I copy multiple files on a Mac, the system tries to copy them all at the same time.
The problem is two-fold.
First of all, when you select multiple files and copy them, they all go into one process with an "all or nothing" approach not unlike…
Kebman
- 525
18
votes
7 answers
unix - split a huge .gz file by line
I'm sure someone has had the below need, what is a quick way of splitting a huge .gz file by line? The underlying text file has 120million rows. I don't have enough disk space to gunzip the entire file at once so I was wondering if someone knows of…
toop
- 365
14
votes
2 answers
How can I identify non-ASCII characters from the shell?
Is there a simple way to print all non-ASCII characters and the line numbers on which they occur in a file using a command line utility such as grep, awk, perl, etc?
I want to change the encoding of a text file from UTF-8 to ASCII, but before doing…
user001
- 3,994
13
votes
3 answers
Getting the process id for current perl script
How do I get the process id for the perl process that's running the current script? getppid() doesn't return the same pid as ps -ea| grep .
Is there is an easy way or do I just run the ps -ea command within my script and trim off the other pieces…
ageis23
- 679
11
votes
1 answer
Perl for matching with regular expressions in Terminal?
I'm trying to familiarize myself a little with Perl to use for regular expression searches in Terminal (Mac). Now, I'm not really looking to learn Perl rigourously, just trying to find out how to do some simple regular expressions.
But I can't…
Anders Svensson
- 339
10
votes
1 answer
Counting occurrences in first column of a file
We have this file:
1 2
1 3
1 2
3 3
52 1
52 300
and 1000 more.
I want to count the number of times each value occurs in the first column.
1 3
3 1
52 2
This means we saw 1 three times.
How can I do that, in Perl, AWK or Bash?
Arash
- 736
10
votes
7 answers
How to convert .xlsx to .txt?
I want to know if there is a Linux tool or a script available to convert .xlsx file to .txt.
user53032
- 101
10
votes
3 answers
Why does a Perl CGI program not write to files on Fedora 40 with Apache?
Last week, I upgraded my Linux file server from Fedora 39 to Fedora 40, and several CGI applications written in Perl stopped working. I first noticed it when Foswiki could not show any pages, because it was unable to open its log file.
After…
Lars Poulsen
- 325
- 1
- 2
- 13
9
votes
3 answers
How to execute a PL file in Linux?
I have a vmware-install.pl file that I need to execute. I double click it but Linux will open it in a text editor for editing.
How to execute this file? Can it be done from GUI?
In file's properties says "allow executing file as program".
I have…
GoUkraineGo
- 2,171