Occam's Razor ha scritto:
> 1. If you have a very large file, named 'ColCheck', tab-delimited, that
> you are asked to process and you know that each line in 'ColCheck' has 7
> columns, and that the values in the 5th column are integers. Using shell
> functions (and standard LINUX/UNIX filters), how would you verify that
> these conditions were satisfied in 'ColCheck'?
These are for bash in linux, GNU grep.
To check that every line has exactly seven columns, we could check it has
exactly six TABs (that is: at least six TABs, but not seven).
Something like:
$ grep -vP '^([^\011]+\011){6}[^\011]+$' ColCheck &>/dev/null || echo OK
Besides, this above requires that no columns are empty.
Then, to check that everything in the fifth column is a digit:
$ [[ $(cut -f5 ColCheck |grep [^0-9]) ]] || echo OK
> 2. In the same file, each value in column 1 is unique. How would you
> verify that?
(( $(wc -l ColCheck |cut -d" " -f1) == $(cut -f1 ColCheck |sort -u |wc -l) )) && echo OK
> 3. How would you write a shell function that counts the number of
> occurrences of the word “SpecStr” in the file 'ColCheckMe'.
If I understand what you want to do:
CountOcc () { echo $(grep -o "SpecStr" ColCheckMe | wc -l) ; }
Then you can use it as a command, or recall its output with command
substitution this way: $(CountOcc)
> 4. How would you do this in PERL?
I don't remember. I give it up.
> 5. How would you log the output (regular output as well as error
> messages) of a UNIX program into a file?
$ unix_command >logfile 2>&1
or:
$ unix_command &>logfile
or (not recommended):
$ unix_command >&logfile
--
Bye, Lem
Ceterum censeo ISLAM esse delendum
_________________________________________________________________
Non sprecare i cicli idle della tua CPU, né quelli della tua GPU.
http://www.worldcommunitygrid.org/index.jsp
http://www.rnaworld.de/rnaworld/ http://home.edges-grid.eu/home/
http://www.gpugrid.net/