read


Using a CSV input file, find all documents that contain any of the items in a cell of a column

The following code will use as input one column from a CSV file, and for each element in the column, it will perform a full-text search in a folder to find all files that contain that element.

#!/bin/bash

#Execution parameters
# 1 - the folder to look in for the element
# 2 - the input file that contains the search terms
# 3 - the column of interest
# 4 - the delimiter to use to find the column
# e.g. ./searchEachElement.sh ./2\ Print/ book.csv 5 ','

folder="$1";
input="$2";
column="$3";
delimiter="$4"

while read -r line; do
  needle=`echo $line | cut -d "$delimiter" -f "$column"`; 
  echo ">>> $needle"
  find "$folder" -type f -exec grep "$needle" -s -l '{}' \;
done < "$input";

More information on the full-text search can be found here.


C: Implicit declaration of function ‘read’ and ‘write’ 6

While working on an socket-based application, we received the following warnings from the compiler:

implicit declaration of function 'read'
implicit declaration of function 'write'

read and write functions are declared in unistd.h which we forgot to include in our code.

Adding the directive


#include <unistd.h>

to the source file that used read and/or write removed the warnings.