Sunday, 14 December 2008

remove recurring numbers

If i want to remove recurring numbers in a line of file1 like.. 123 456 789 and replace it with only 123

then do this,

sed 's/\([0-9]*\) \([0-9]*\) \([0-9]*\)/\1/' file1 > tmp

Explanation : I have used TRE (tagged regular expression) to remember the patterns and replaced them with a first group value through "\1".This way we can have up to "\9" values. The result file is put to a "tmp" file.

Note : Here after I would replace "Explanation" with "Exp" to minimize my effort.

No comments:

Post a Comment

Tweets by @sriramperumalla