Hot answers tagged

61 votes

When to use Bash and when to use Perl/Python/Ruby?

TL;DR - use bash only for installing a better language (if it isn't already available), otherwise you're wasting unrecoverable, precious human time. If you can't do it on the command line by hand ...
33 votes
Accepted

Command vs program?

In simple terms, a command is an instruction (or a set of instructions) to be carried out by a computer. Stand-alone commands Fundamental Unix utilities such as ls, ln, etc. are (usually) written in ...
18 votes

Removing ANSI color codes from text stream

ansi2txt https://unix.stackexchange.com/a/527259/116915 cat typescript | ansi2txt | col -b ansi2txt: remove ANSI color codes col -b: remove ^H or ^M update: about col handle tabs and space //...
  • 323
12 votes

How to cut a file to a given size under Linux?

You can use tail to cut last 1000 bytes, example: tail -c 1000 file > file2 the -c outputs final 1000 bytes of the file, for more options: man tail To replace original file with the file you ...
10 votes

Removing ANSI color codes from text stream

I believe this is an authoritative removal of all ANSI escape sequences: perl -pe ' s/\e\[[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e]//g; s/\e[PX^_].*?\e\\//g; s/\e\][^\a]*(?:\a|\e\\)//g; s/\e[\[\]A-...
  • 316
10 votes
Accepted

Add a new element to existing JSON array

Do not try to parse JSON text with standard text processing tools like awk, sed or without JSON modules in perl, as they are non JSON syntax aware. jq is a lightweight JSON processor that allows you ...
  • 240
8 votes

Removing ANSI color codes from text stream

commandlinefu gives this answer which strips ANSI colours as well as movement commands: sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" For just colours, you want: sed "s,\x1B\[[0-9;]*m,,g"
  • 2,194
8 votes

Perl script can't locate Env.pm in @INC

Install the perl-Env package to obtain Env.pm. yum install perl-Env You can also use the whatprovides feature of yum to see what packages provide files, yum whatprovides */Env.pm perl-Env-1....
  • 116
6 votes

Autoformat for Perl in Vim

Assuming you're on a Unix-like operating system... Get hold of perltidy (a highly customizable Perl code indenter/formatter). Then update your ~/.vimrc file to include the following: filetype plugin ...
  • 2,283
6 votes

When to use Bash and when to use Perl/Python/Ruby?

In my experience bash versus python is a trade off between development time and flexibility. A rudimentary solution to a problem can usually be established in a bash script more quickly than it can be ...
  • 61
6 votes

Can I use perl regular expressions in the vim command line?

Here's a solution from http://vim.wikia.com/wiki/Perl_compatible_regular_expressions :perldo s/(\w+)/\u$1/g (Verify with :ver that +perl or +perl/dyn is compiled in.)
5 votes
Accepted

How to point MacVim to the right perl on OSX 10.10?

I have solution, not a great one, but it works for fixing MacVim. brew uninstall macvim brew install macvim brew linkapps macvim Worked for me. Hopefully, the related question above will be the ...
5 votes

How to fix perl error Test::More dependency failed?

Try to yum install perl-Test-Simple This should install your missing perl module Test::More
4 votes

unix - split a huge .gz file by line

Directly split .gz file to .gz files: zcat bigfile.gz | split -l 400000 --filter='gzip > $FILE.gz' I think this is what OP wanted, because he don't have much space.
4 votes

Removing ANSI color codes from text stream

There's also a dedicated tool for the job: ansifilter. Use the default --text output format. ref: https://stackoverflow.com/a/6534712
  • 489
4 votes
Accepted

Using Perl regex over multiple lines

Without any other options, -p processes the input line by line. No line can contain anything after the \n. You have to change the record separator: perl -i~ -0pe 's/ab\nba/a a/' file.txt -i~ will ...
  • 18k
4 votes
Accepted

Accidently running perl-script with sh, how to detect that and take actions?

One option would be to use the perl -x option like this: #!/bin/bash perl -x "$0" exit #!/bin/perl #perl code goes here On my system that works for either sh or perl.
4 votes

Problems executing perl on git for windows bash

I was using Strawberry Perl so if you have that one and want to use Perl on MSYS2 or Git for Windows you have to specify an ENV variable called PERL5LIB with the route to your modules on Strawberry ...
  • 183
3 votes

Getting the process id for current perl script

In addition to $$ as Ian mentions, I'm a fan of making code more readable. To that end, Perl supports the mnemonic $PID if you use English to enable the aliases.
  • 237
3 votes

How to cut a file to a given size under Linux?

The answer above citing truncate is nice. dd will also do the job: dd if=test.txt of=test2.txt bs=1 count=8 mv test2.txt test.txt
3 votes

When trying to start Apache - Cant load “Magick.dll” for module Image::Magick?

Take a look at this posting: The solution to this problem was to reboot Windows (stopping and starting the Apache 2.2 Windows service also didn't make a difference), even though the path wasn't ...
  • 15.4k
3 votes
Accepted

How to match parameter and replace the value after "=" separator

Changing an IP Address perl -p -i -e 's/VIP_IP=[[:digit:].]+/VIP_IP=192.17.200.100/' file.txt Or: perl -i -pe 's/(VIP_IP=)[[:digit:].]+/${1}192.17.200.100/' file.txt Or, if the new IP is in a ...
  • 16.3k
3 votes

Is there a way to run a perl script on a windows system without having to install anything?

You can use the PortableZIP edition of Strawberry Perl, available here. There's also a ZIP edition that doesn't require admin privileges, but you need to run some post-install scripts manually after ...
  • 55.4k
3 votes
Accepted

When I run a git hook in a repo on a network share: which binaries are used?

If it’s a regular (SMB/CIFS) network share, it’s executed on the client. If you use Git via SSH or HTTPS, Git (possibly an alternative implementation) is running on the remote side and executes hooks....
  • 56.9k
3 votes

Perl IRC Bot running on the machine

(Yes, it dosen't answer what he's asking. Its answering what he needs to know) Nuke it from orbit... Its the only way to be sure. You can't really trust a compromised system and your problems are ...
  • 125k
3 votes
Accepted

how to align lines to the left side with sed or perl one line liner

This will delete all spaces and tabs at the beginning of every line: sed 's/^[ \t]*//' where ^ matches the beginning of a line [ \t] matches a space or a tab * makes the previous […] block work ...
3 votes
Accepted

Why is this Perl command failing on the Windows command line?

The other answer is NOT correct. If you do that you'll still get errors when running in cmd C:\Users>dir | perl -pe 's/(.)(.*)_(\d{4})(\d{2})(\d{2})_(\d+).jpg/\u$1$2,$3-$4-$5,$6,$&/' Can't ...
  • 24.7k
3 votes

500 Internal Server Error when run perl file and no access to command line

Perhaps your file is being run, and the problem is that it doesn't output a valid HTTP response? I'd fix that first, though I'm not sure if the file is being run or not. This is close to the minimal ...
  • 389
2 votes

Perl command not found

Try: find / -type f -name '*perl*' 2>/dev/null This is a wider search scope than that proposed by Gilles Quenot, but it will only return files (not directories) and also remove any "Permission ...
2 votes

How to execute a PL file in Linux?

"How to execute a PL file in Linux?" A PL file in Linux (filename ending with .pl) is very likely a Perl-program. So run it with perl like this: perl vmware-install.pl It's often also possible to ...
  • 509

Only top scored, non community-wiki answers of a minimum length are eligible