Apr 29, 2002 #1 123jk Programmer Joined Mar 22, 2001 Messages 7 Location IN hi, I need to remove duplicate word and also invalid data from the string for eg, x="1 2 3.4 5 6 1 3" the o/p should be 1 2 5 6 3 removing all the duplicates and invalid data( valid data - numbers no floating values) How to do this.. Thanks, jaya
hi, I need to remove duplicate word and also invalid data from the string for eg, x="1 2 3.4 5 6 1 3" the o/p should be 1 2 5 6 3 removing all the duplicates and invalid data( valid data - numbers no floating values) How to do this.. Thanks, jaya
Apr 29, 2002 #2 toolkit Programmer Joined Aug 5, 2001 Messages 771 Location GB This would be quite easy using perl: Code: #!/usr/bin/perl -w %seen = (); foreach( @ARGV ) { next unless /^\d+$/; push @num, $_ unless $seen{$_}++; } print "@num\n"; Used like: Code: ./test.pl 1 2 3.4 5 6 1 3 Returns: Code: 1 2 5 6 3 Cheers, Neil Upvote 0 Downvote
This would be quite easy using perl: Code: #!/usr/bin/perl -w %seen = (); foreach( @ARGV ) { next unless /^\d+$/; push @num, $_ unless $seen{$_}++; } print "@num\n"; Used like: Code: ./test.pl 1 2 3.4 5 6 1 3 Returns: Code: 1 2 5 6 3 Cheers, Neil
Apr 29, 2002 Thread starter #3 123jk Programmer Joined Mar 22, 2001 Messages 7 Location IN Hi, Thanks for the response. I need this to be implemented through shell script. I think it can be implemented easily in 'sed'. but i don't have much experience in using sed. Thanks, jaya Upvote 0 Downvote
Hi, Thanks for the response. I need this to be implemented through shell script. I think it can be implemented easily in 'sed'. but i don't have much experience in using sed. Thanks, jaya
Apr 29, 2002 #4 vgersh99 Programmer Joined Jul 27, 2000 Messages 2,146 Location US echo $x | nawk ' { for (i=1; i <= NF ; i++) $i=(match($i, /\./) ? "" : $i); print} ' Upvote 0 Downvote