How do you use one-liners (-n -p -a -F) with a short example?

Perl one-liners are powerful and concise commands that let you quickly manipulate text files directly from the command line. Here’s a concise explanation of some options:

  • -n: Processes each line of input in a while loop.
  • -p: Similar to -n, but automatically prints each line after processing.
  • -a: Automatically splits input lines into the @F array, allowing easy access to fields.
  • -F: Specifies the input field separator for -a.

Example:

# Example using Perl one-liners
# Extracting the first column from a CSV file:
perl -F, -anE 'say $F[0]' file.csv
# The above command will print the first field from each line in file.csv.

Perl one-liners text processing command line scripting