Hot answers tagged

62

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 without mistakes, don't script with bash/shell. It's 2015, so I'd consider the following: memory overhead Ruby/Python runtime memory overhead compared to bash is ...


33

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 C and compiled to be stand-alone executable programs that don’t require an interpreter to be executed; they usually require certain library files to be ...


19

I like the criteria set out in this blog post. If there aren’t any arguments to pass in, it’s probably a shell script. If there isn’t much for control logic (besides a single loop or if/else) it’s probably a shell script. If the task is automation of command-line instructions it’s almost definitely a shell script.


14

I had the same problem. I did: sudo port deactivate -f subversion-perlbindings-5.12 which allows me to install the new version of the perl bindings.


13

This was fixed by installing libcrypt-devel. Then everything worked just fine... So problem solved! This explains it better: Re: Difficult compiling Package::Stash::XS


12

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 //mentioned by @DanielF 〇. about col handle spaces and tabs col -bx replace '\t' to ' ', col -bh replace ' ' to '\t'. // seems col can't keep space/tabs as it is, it's a ...


12

Run this instead: ./vmware-install.pl The ./ refers to the current directory. If you run it without ./, Linux will look for a program called vmware-install.pl in your executable path, but the current directory is never in the path by default (for security reasons).


11

If you prefer something simple, you could use my strip-ansi-cli package (Node.js required): $ npm install --global strip-ansi-cli Then use it like this: $ strip-ansi < colors.o Or just pass in a string: $ strip-ansi '^[[37mABC^[[0m'


11

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 just generated: mv file2 file


9

I found this Perl versus Bash analysis useful... http://blogs.perl.org/users/buddy_burden/2012/04/perl-vs-shell-scripts.html For convenience, I'm copying a summary of that author's 1) when bash is better findings and 2) when perl is better conclusion... When Bash is Better... Job Failure Commands on Exit Processing Job Output Lines Here Documents File ...


9

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 manipulate content on the fly. For e.g. your requirement could be simply written as jq --arg new "arn:aws:iam::xxxxxxx:role/3" '.Statement[].Principal.AWS? += ...


8

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"


7

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-Z\\^_@]//g;' (Please note that perl, like many other languages (but not sed), accepts \e as the escape character Esc, \x1b or \033 by code, shown in terminals ...


6

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 in a python script. Python will tend to make you think more about the structure of your solution than will the equivalent bash script. Python has more ...


6

So the solution was..... install TermReadKey Cygwin package from cygwin installer. Such an easy solution :) Thanks to atrigent for this idea!


6

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.04-2.el7.noarch : Perl module that imports environment variables as scalars or arrays Repo : base Matched from: Filename : /usr/share/perl5/vendor_perl/...


5

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 indent on autocmd FileType perl setlocal equalprg=perltidy\ -st This will allow you to mark whatever block of Perl code you want and then reformat it by ...


5

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 answer to my Perl version problem.


5

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


4

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

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


4

Use the eregex.vim plugin. It's very useful and I have had no problems with it.


4

Use pgrep instead: pgrep -g 18322 From man pgrep: -g, --pgroup pgrp,... Only match processes in the process group IDs listed. Process group 0 is translated into pgrep's or pkill's own process group. Alternatively, you can just parse the ps output in simpler ways: ps xh -o pgrp,pid | awk '$1==18322{print $2}' Or just simplify ...


4

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 modify the file "in place", leaving a backup behind (named file.txt~) -0 makes the character \0 the input record separator. The important thing is it doesn't ...


4

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

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 Perl or the Perl distribution you have. . export PERL5LIB=/c/Strawberry/perl/vendor/lib which to be permanent on your system has to be located on your .bashrc ...


3

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

For JSON.pm on ubuntu system, you should install libjson-perl package: apt-get install libjson-perl You can find which ubuntu package holds your file thanks to: apt-file search JSON.pm


3

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.


3

I haven't been able to get the Finder's spotlight search to list .bashrc either (perhaps it's finding it, but not displaying because it's invisible?). But the command-line interface to spotlight... well, it can be convinced to show it. This works: $ mdfind kMDItemFSName = ".bashrc" /Users/gordon/.bashrc But for some reason the -name option doesn't show it: ...


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