LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Error in replacing special chars using awk (https://www.linuxquestions.org/questions/linux-general-1/error-in-replacing-special-chars-using-awk-634184/)

linux_vidhyarthi 04-09-2008 09:22 AM

Error in replacing special chars using awk
 
I have a file with following data :
a$cd
e%gh
I am trying to replace the special chars with space.
When I execute the following command these chars are replaced :
awk '{gsub(/[\041-\177]/,"b",$0);print $0}' temp.txt

Result:
abcd
ebgh

But when I execute
awk '{gsub(/[\041-\175]/,"b",$0);print $0}' temp.txt

Result:
a$cd
e%gh

these chars are not replaced.Could someone tell me if I am doing any mistake.

Thanks in advance

colucix 04-09-2008 12:11 PM

I have to investigate the reason of this strange behaviour more in depth, but in the meanwhile why don't use
Code:

gawk '{gsub(/[[:punct:]]/," ",$0); print}' temp.txt

linux_vidhyarthi 04-09-2008 07:39 PM

Thanks,your solution worked.
If you find the reason for the strange behaviour please let me know.


All times are GMT -5. The time now is 02:21 PM.