Sunday, June 14, 2009

alphabetical order words...

Hiii Friends..

This time i have come with a prob..

Prob is : You have to print the all worlds in a file that are in increasing order..
i.e. abcd.. qrstz.. but it can't be like dcefgh...because c followed by d contradict the rules.

Thak you In Advance....

1 comment:

  1. One of possible sol is..
    cat testfile
    |
    egrep -ow "a?b?c?d?e?f?g?h?i?j?k?l?m?n?o?p?q?r?s?t?u?v?w?w?x?y?z?"

    in this abve code..
    -o is for outputing only matching part..
    -w for matching only word not any part of word...
    ? character used here in reg. expression mean that one of more occurences of the previous character..

    this will find all such word in testfile..can be applied..to many file simultaneously..

    the main logic is to use extended regular expression.

    "a?b?c?d?e?f?g?h?i?j?k?l?m?n?o?p?q?r?s?t?u?v?w?w?x?y?z?"

    we can use this either with..
    AWK
    SED
    GREP with -E option..
    EGREP to get the right answer..

    ReplyDelete