Reputation: 23
I have a file where each record has a word "TST_BI|"
and I need to use as a delimiter and populate the value after this string to a file . There is only one occurrence of this string in each record.
It is working fine in AIX environment with below command.
awk -F "TST_BI|" '{print $2}' file.txt
.
But when I migrated the code to Linux and tried the same, command is NOT working, where the value "|"
is also getting populated. Below are the output from both AIX and Linux
Input :
<14>1 2017-08-31T04:13:47.2345839+00:00 loggregator ecsdasc0985-cs656-4asdsds-asds-asdasg6ds73 [DEV/2] - - TST_BI|DATE~2017-08-31 04:13:47,095|TIMESTAMP~04:13:47|TEST_ID~biTestExecutor-2|COUNTRY_CODE~XX|GROUP_TESTS~BZAG
OutPut from AIX :
DATE~2017-08-31 04:13:47,095|TIMESTAMP~04:13:47|TEST_ID~biTestExecutor-2|COUNTRY_CODE~XX|GROUP_TESTS~BZAG
With same command, Linux Output is
|DATE~2017-08-31 04:13:47,095|TIMESTAMP~04:13:47|TEST_ID~biTestExecutor-2|COUNTRY_CODE~XX|GROUP_TESTS~BZAG
A pipe is getting populated and which is not treating as delimiter.
Can anyone please help?
Upvotes: 1
Views: 87
Reputation: 92884
vertical bar char |
specified with adjacent characters is treated as regex alternation operator/alternation group. In such case, to treat |
literally - it should be escaped \\|
or put into a character class [|]
:
awk -F'TST_BI[|]' '{print $2}' file.txt
The output:
DATE~2017-08-31 04:13:47,095|TIMESTAMP~04:13:47|TEST_ID~biTestExecutor-2|COUNTRY_CODE~XX|GROUP_TESTS~BZAG
Upvotes: 3