Are file descriptors shared when fork()ing?

From fork(2): * The child inherits copies of the parent’s set of open file descrip- tors. Each file descriptor in the child refers to the same open file description (see open(2)) as the corresponding file descriptor in the parent. This means that the two descriptors share open file status flags, current file offset, and signal-driven … Read more

Variables as commands in Bash scripts

Simply don’t put whole commands in variables. You’ll get into a lot of trouble trying to recover quoted arguments. Also: Avoid using all-capitals variable names in scripts. It is an easy way to shoot yourself in the foot. Don’t use backquotes. Use $(…) instead; it nests better. #! /bin/bash if [ $# -ne 2 ] … Read more

Simple glob in C++ on unix system?

I have that in my gist. I created a stl wrapper around glob so that it returns vector of string and take care of freeing glob result. Not exactly very efficient but this code is a little more readable and some would say easier to use. #include <glob.h> // glob(), globfree() #include <string.h> // memset() … Read more

Extract specific columns from delimited file using Awk

I don’t know if it’s possible to do ranges in awk. You could do a for loop, but you would have to add handling to filter out the columns you don’t want. It’s probably easier to do this: awk -F, ‘{OFS=”,”;print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$20,$21,$22,$23,$24,$25,$30,$33}’ infile.csv > outfile.csv something else to consider – and this faster and more … Read more