please advice how to delete all characters in file except numbers and “.”
- Should be implemented by sed or awk or perl ( one line ) or any other idea , so I will add the syntax in my ksh script
remark – the solution must be according to the example in target file ( see spaces in this example ) , so the other characters ( non dot or numbers ) will be replaced by one space
for example the original file:
192.0.22.1++0.1 e32)5.500.5.5*kjcdr ##@$1.1.1.1+++jmjh 1.1.1.1333 33331.1.1.1 @5.5.5.?????? ~3de.ede5.5.5.5 1.1.1.13444r54 192.9.30.174 &&^#%5.5.5.5 :5.5.5.5@%%^^&* :5.5.5.5: **22.22.22.22 172.78.0.1()*5.4.3.277 3.3.3ki.3.
the target file after delete all characters except numbers and “.” charter
192.0.22.1 0.1 32 5.500.5.5 1.1.1.1 1.1.1.1333 33331.1.1.1 5.5.5. . 5.5.5.5 1.1.1.13444 54 192.9.30.174 5.5.5.5 5.5.5.5 5.5.5.5 22.22.22.22 172.78.0.1 5.4.3.277 3.3.3 .3.
Answer
Use a negated group [^.0-9]
which means anything except dot and numbers. To cleanup infile
do:
sed 's/[^.0-9][^.0-9]*/ /g' infile
Edit
To replace sequences of the negated group with one space you can use the updated answer.
Attribution
Source : Link , Question Author : yael , Answer Author : Thor