Tuesday, June 10, 2014

Unix ---> More tricks

Every word of a file can be placed on a separate line by typing

    cat old_filename | tr -cs A-Za-z '\012' > new_filename
The following lists all words in filename in alphabetical order.

    cat filename | tr -cs A-Za-z '\012' | tr A-Z a-z | sort | uniq
You can find out when the file .rhosts was last modified by typing

    echo .rhosts last modified on `/bin/ls -l .rhosts | cut -c33-44`
Typing head -n displays the first n lines of a file. And typing last lists the last logins.

    grep '^...............$' /usr/share/dict/words  | grep -v '\(.\).*\1'
returns all the words in /usr/share/dict/words that are fifteen letters long and do not contain the same letter twice.

    grep 'a[^aeiou]*e[^aeiou]*i[^aeiou]*o[^aeiou]*u' /usr/share/dict/words
returns all the words in /usr/share/dict/words that contain all of the vowels in the correct order.

No comments:

Post a Comment