awk - special character as delimiter
My file awk_test.txt contains:
Quote:
My command was: Code:
awk 'BEGIN {FS ="'"} {print $1, $2}' awk_test.txt Code:
> This is working (field separator in this case is "space": Code:
awk 'BEGIN {FS =" "} {print $1, $2}' awk_test.txt tom'java'mark eve mark Could you help, please? |
There might be several ways. One is to let the shell handle the escape:
Code:
awk 'BEGIN{ FS="['\'' ]"; OFS="\t"; } { print $1, $2, $3; }' |
probably:
Code:
awk -F"'" '{print $1, $2}' awk_test.txt |
Okay. It works. Thank you very much for your answer.
I know that in the character range I must use escape character at some special character: -, ^, }, ]. I tried to use only escape like: Quote:
So why must use Quote:
|
Quote:
|
remember, between ' ': 'protected text' the protected text will not be evaluated by the shell, and it must not contain ', because that is the delimiter itself ( = beginning and the end)
Therefore you need to do the following: Code:
awk # the command itself |
Yes, anything between two single quotes is protected and won't be processed. It will be taken literally instead:
Code:
$ a='\"' In the second example it is processed. |
Okay. Now I understand :)
Thank you. |
All times are GMT -5. The time now is 09:53 AM. |