Aho, Weinberger, and Kernighan (AWK)
The full form of the `awk` command is "Aho, Weinberger, and Kernighan." The name "awk" is derived from the initials of its three creators: Alfred Aho, Peter Weinberger, and Brian Kernighan. They developed the `awk` programming language and command-line tool in the 1970s, which has since become widely used for text processing and data manipulation tasks. The `awk` command is available on most Unix-like systems, including Linux.
The `awk` command can also be used to find and replace text in Linux. Here's an example:
Let's say we have a file named `example.txt` with the following content:
Hello, World!
To replace the word "World" with "Lalatendu!" using `awk`, you can use the following command:
awk '{ gsub("World", "Lalatendu!"); print }' example.txt
The output will be:
Hello, Lalatendu!!
In the `awk` command:
- `gsub("World", "Lalatendu!")` is the function used to globally substitute "World" with "Lalatendu!".
- `print` is used to output the modified line.
By default, `awk` processes each line in the file. If you want to modify the file in-place, similar to the `-i` option in `sed`, you can redirect the output to a temporary file and then overwrite the original file:
awk '{ gsub("World", "Lalatendu!"); print }' example.txt > temp.txt && mv temp.txt example.txt
This command performs the find and replace operation using `awk` and redirects the output to a temporary file called `temp.txt`. Then, it replaces the original file with the modified temporary file using `mv`.
Please note that as with any in-place modification, it's important to be cautious and make backups of important files before performing such operations.
The `awk` command offers powerful text processing capabilities beyond simple find and replace. It allows you to work with fields, perform calculations, apply conditions, and more. You can refer to the `man awk` command for more details and explore the various functionalities provided by `awk`.