How to replace pattern?

1 | HTTP | ^~
1 | HTTP | ^~&<?1;?;-unp~xn~lP4WM}~!0%#8?;+5vl9`#ep3q6X1772goci3fj`nc7M1?`"*"#&1 ?;?=>k4NQ="#$3(> | 20180115 | 17
1 | HTTP| ^~�3�������������󬩵���粷�����������𶯰����ܬ�� | 20180123 | 07
1 | HTTP | 5g | 20180123 | 09
1 | HTTP | `6$pct{z`ChagykbmsvDlbeu0)d&`{f/d80l18m`29VYei1&49dw1/g~fOvt!%3iv"3U;9(!>%4pfbbyn | 20180117 | 14
1 | HTTP | ^~!7c{cxg | 20180117 | 11
1 | HTTP | ^~89>0&9fjefdT\3=2&=86sgzd | 20180117 | 12
1 | HTTP | ^~8)rzk)+tar.8?0,%:?&3&<)>4.81;1#++(pqzwglgl:*fq05nfu13;1p17:g&hal5u?b<a&<bm`%++(cxnhzk`aj | 20180115 | 12
1 | HTTP | `a`ih$mmdzb | 20180117 | 17
1 | HTTP | ^~�a>mj[^RTYU\oe#WRNEH]C_D | 20180123 | 12
1 | HTTP | ^~Cookie:**** | 20180117 | 13
1 | HTTP | ^~Cookie:***�H�O��:��pd�����L]��Ie(���T��MT��(���� | 20180117 | 18
1 | HTTP | ^~Cookie:****N:^L:��4R�W0�{б�#��Z��r | 20180118 | 00
1 | HTTP | Rejection Reason": "Malformed line with incorrect number of fields (expected=35,actual=17) | 22974464 | 24
1 | HTTP | Rejection Reason": "Malformed line with incorrect number of fields (expected=35,actual=17) | 35905339 | 66
1 | HTTP | Rejection Reason": "Malformed line with incorrect number of fields (expected=35,actual=17) | 40861664 | 30
1 | HTTP | Rejection Reason": "Malformed line with incorrect number of fields (expected=35,actual=18) | 03727721 | 39
2 | HTTP | Rejection Reason": "Malformed line with incorrect number of fields (expected=35,actual=19) | 20170727 | 12
9 | HTTP | Rejection Reason": "Malformed line with incorrect number of fields (expected=35,actual=19) | 20180115 | 00

Tried gsub to eliminate but it is not working.

 awk -F '[|]' '{gsub(/^~*/,"",$3)}; {print $3}' filename

Please guide how should i handled the regex pattern strings.

Which pattern? Please be way more specific and precise.

At the beginning of a regular expression the ^ has the special meaning "at the very beginning".
Needs to be escaped

gsub(/\^~/,"",$3)

The following has the special and the literal ^

gsub(/^ \^~/,"",$3)

Meaning: at the very beginning of field 3 there must be a space then a ^ then a ~
Because all what matches is substituted, the space is also substituted. Can be added in the substitution string.

1 Like

strings for field $3 with start with ^~ should be replaced by "Unkown Reason"

As MadeInGermany already suggested, try:

awk '{sub(/^ \^~/," Unknown Reason",$3)}1' FS=\| OFS=\| file

or

awk '$3~/^\^~/{$3="Unknown Reason"}1' FS=' *\\| *' OFS=' | ' file

or

awk '$3~/^ \^~/{$3=" Unknown Reason"}1' FS=\| OFS=\| file

Misread the requirement, apologize.

Regards
Peasant.