Awk – replace number greater than 17 digits in a column with –

awkvariable substitution

I have a CSV file containing timestamp values in UTC which I need to replace with -. There may be more than one timestamp in the same column, can you please let me know how do I do that?

For example, this is one column in a CSV file:

+1234|2|12|1|1|1537820114232192380|0  +1234|2|12|1|1|1537820113262689150|0

The output should look like:

+1234|2|12|1|1|-|0  +1234|2|12|1|1|-|0

Best Answer

Since that is inside a file, it is faster to use sed:

sed -i 's/[0-9]\{18,\}/-/g' file

Understand that the -i option will change your file. If you want to see what it does before committing remove the -i.

Note that in BSD, the -i should have a parameter, so use: -i ''.

Awk could also do it:

<file awk '{gsub("[0-9]{18,}", "-")}1'  >newfile
Related Question