1. Perl
  2. One liner

Perl One Liner - Explanation of e Options

Perl has a feature called Oneliner that allows you to execute Perl scripts from the command line. Windows doesn't have the convenience of commands like Linux, so you can do something similar with Perl's one-liner. Introducing a one-liner that is often used in Perl.

What is one - liner?

A one-line Perl script that can be executed directly from the command line

- e

If -e is specified, subsequent Perl scripts will be executed directly.

- n

If -n is specified, the subsequent Perl script will be enclosed in "while (<>) {}" using the line input operator in while statement. It will be a script.

One - liner commentary

perl -ne "print if (/ search /)" inputfile.txt> outputfile.txt

This sentence is the same as 1 and 2 below.

1: grep.pl

# Each line of the file given by the argument is passed to <>.
# Each line received by <> is passed to $_ in a loop.
# $_ Is implicitly used for regular expression //
# $_ Is implicitly used as the argument of print.
while (<>) {
  print if/search/;
}

2: Execution

perl grep.pl inputfile.txt> outputfile.txt

Extract lines containing the specified string to grep with Perl

Let's use a function called One Liner to extract the line containing the string specified in Perl.

One liner to realize grep(used from command prompt)

perl -ne "print if (/ search /)" inputfile.txt> outputfile.txt

inputfile.txt

search1
kjhkh
search2
lkjlkjl
oiuyyiu
search3

Cat at the Windows command prompt

This time I will introduce a one-liner for doing the same thing as cat on Linux on Windows. The cat command is a command that allows you to combine the contents of files. To cat at the command prompt:

perl -ne "print" file1 file2 file3> output.txt

I was able to combine the contents of the files.

Related Informatrion