Recognize input escape sequence

I see awk can recognize escape sequences

$ awk 'BEGIN {print "foo\nbar"}' foo bar 

However, from input it is not

 $ awk '{print $1}' <<< 'hello\nworld' hello\nworld 

Can control sequences be recognized from the input?

+4
source share
3 answers

This also works with variables.

 $ set 'hello\nworld' $ printf %b "$1" | awk '{print $1}' hello world 
0
source

You need to do something like this -

 [jaypal:~/temp] awk '{print $1}' <<< $'hello\nworld' hello world 

bash(1)

+3
source

The line used here does not extend the escape sequence of the newline in the actual newline. Try the following:

 `echo -e "hello\nworld" | awk '{print $1}'` 

Or alternatively:

 awk '{print $1}' <<< "hello world" 
0
source

Source: https://habr.com/ru/post/1484317/


All Articles