-3

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.

Raj
  • 7
  • 3
  • 1
    Please, 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 Answers1

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