Hello ,
i have a text file like this :
A123 c12AB c32DD aaaa
B123 23DS 12QW bbbb
C123 2GR 3RG cccccc
i want to remove the numbers from second and third column only.
i tried this :
perl -pe 's/[^A-Za-z\s]//g' file.txt > newfile.txt
but it will remove the number from all the file , but i want to keep the numbers in the first column,
thanks
awk '{gsub("[0-9]*","",$1);gsub("[0-9]*","",$3)}1' infile.txt >newfile.txt
---------- Post updated at 12:57 PM ---------- Previous update was at 12:56 PM ----------
awk '{gsub("[0-9]*","",$2);gsub("[0-9]*","",$3)}1' infile.txt >newfile.txt
---------- Post updated at 01:00 PM ---------- Previous update was at 12:57 PM ----------
Alternately
awk '{gsub("[[:digit:]]",z,$2);gsub("[[:digit:]]",z,$3)}1' file.txt >newfile.txt
thanks for you reply ,
it works , but it places a point(.) in front of new values in 2nd and 3rd column .
and can you please explain the command
The command should not add a dot in front of new values in 2nd & 3rd columns...
Which plateform do you run?
Please copy/paste the command you have tried
i used this :
awk '{gsub("[0-9]*","",$2);gsub("[0-9]*","",$3)}1' infile.txt >newfile.txt
and i have ubuntu 9.10 running on virtual box
Could you please copy paste all that you have as input as well as result of the command ?
---------- Post updated at 01:34 PM ---------- Previous update was at 01:33 PM ----------
try the same without the wildcard :
awk '{gsub("[0-9]","",$2);gsub("[0-9]","",$3)}1' infile.txt >newfile.txt
2 Likes
it works now , i just added also the point to be removed , and it works , thanks
# cat file1
A123 c12AB c32DD aaaa
B123 23DS 12QW bbbb
C123 2GR 3RG cccccc
# i=1;sed 's/\(^[^ ]*\) *[^ ]* *[^ ]*\(.*\)/\1\2/' file1|while read -r l ; do echo "$l"|sed "s/ /$(sed -n ''$i' s/^[^ ]*\( *[^ ]* *[^ ]*\).*/\1/p' file1|sed 's/ /_/;s/[0-9]//g;s/_/ /') /" ;((i++));done
A123 cAB cDD aaaa
B123 DS QW bbbb
C123 GR RG cccccc