0

I have to test several shell commands on the real file that I create to make sure they work. I have a windows and a mac computers. Please, provide me step by step instructions on how to do it preferably on mac.

Here is a list of problems and commands that I have to test to make sure they work properly:

1) There is a huge tab-delimited file "fileGrand", it has 10 columns, the values in 6th column are integers. How to verify that all of these conditions were satisfied?

nawk 'NF != 10 {printf("[%d] has invalid [%d] number of fields\n", FNR, NF)} $6 !~ /^[0-9]+$/ {printf("[%d] 6th field is invalid [%s]\n", FNR, $6)}' fileGrand

2) The same file. Each value in column 3 is unique. How to verify that?

awk -F$'\t' '$3 in a {exit 3} {a[$3]}' fileGrand

3) Count the number of occurrences of the word "blue" in the file fileGrand.

CountOcc () { echo $(grep -o "blue" fileGrand | wc -l) ; }

4) Log the output and error message of a program into a file.

unix_command >logfilename 2>&1
Dummy00001
  • 16,630
  • 5
  • 41
  • 63
icittar
  • 31
  • 5

0 Answers0