I have file in UNIX with many records having pipe delimiter. I want to remove non alpha numeric and non special character from the value of column number 20 which contains phone number and will do right trim 10 digit.
Asked
Active
Viewed 94 times
-3
-
1Please, show us the code of what you tried. Give an short sample of input and the expected output corresponding to that input, and we will help you. – Pierre François Dec 23 '20 at 19:25
-
See https://stackoverflow.com/q/45444988/2191572. If you need a comprehensive regex for CSV then see https://stackoverflow.com/q/18144431/2191572. You've shown zero attempt so it is impossible to guess how close you are to achieving your goal. Good luck! – MonkeyZeus Dec 23 '20 at 19:26
-
for example the content of a pipe delimited file as below ABCD|123|HI|123ABCD#$1234|JAY GEFR|245|BY|2472462342#$41|JAM her you can see the 4th column having alphanumeric and special character ,I want to keep only the numeric value – Raj Dec 23 '20 at 19:41
1 Answers
0
awk -F\| '{ OFS="|";gsub(/[[:alpha:]]|[[:punct:]]/,"",$4);$0=substr($4,(length($4)-10),length($4)) }1' file
Set the file delimiter to | and then use gsub to substitute any alpha character or punctuation to empty characters. Print lines.

Raman Sailopal
- 12,320
- 2
- 11
- 18
-
how to keep only 10 digit from the right for that 4th column.I mean how to use substr here to achieve that. – Raj Dec 23 '20 at 20:37
-
-
could you please share the full command adjusting in awk -F\| '{ OFS="|";gsub(/[[:alpha:]]|[[:punct:]]/,"",$4) }1' file – Raj Dec 23 '20 at 20:46
-