Escape sequences
When using regular expressions and strings, certain characters cannot be included literally in string constants ("hello"
) or regular expression constants (/hello/
). To specify the characters for which there may not be other notations, they are represented as escape sequences. Escape sequences begin with a backslash ('\'
). For example, it can represent that an \n
newline character is used, which otherwise cannot be represented in strings or regular expressions. Similarly, \b
stands for backspace, \t
stands for tab, and \/
represents a forward slash. They are quite useful in generating formatted output.
For example, to insert a new line after each line of the emp.dat
file, we can use the \n
escape sequence, as follows:
$ awk '{ print $0"\n" }' emp.dat
The output on execution of the given code is as follows:
Jack Singh 9857532312 [email protected] M hr 2000 Jane Kaur 9837432312 [email protected] F hr 1800 Eva Chabra 8827232115 [email protected]...