March 2018
Beginner to intermediate
416 pages
9h 24m
English
We can use AWK to create and execute shell commands, such as the mv command for renaming, by piping them to shell sh for executing them. We should always check a command by printing the output before piping it to sh to avoid any typo errors, as follows :
First, we will just use the print statement to display the command result and not execute it on the command prompt, as follows :
$ ls | awk '{ printf("mv \"%s\" \"%s\"\n", $0, toupper($0)) }'
If we confirm the command line built using AWK, then we can execute it by piping the AWK output to the sh command, as follows:
$ ls | awk '{ printf("mv \"%s\" \"%s\"\n", $0, toupper($0)) }' | sh
In out next rename examples, we substitute the occurrence of spaces ...
Read now
Unlock full access