------------------------------------------------------------------------ PROBLEM: Identify files with zero length and delete them ------------------------------------------------------------------------ $ touch a b c d $ cat > 1 Hello Kitty cntrl D $ ls -l total 8 #this line appears only with "ls -l" or "ls -l *" -rw-r--r-- 1 srk staff 7 Nov 12 21:39 1 -rw-r--r-- 1 srk staff 0 Nov 12 22:13 c -rw-r--r-- 1 srk staff 0 Nov 12 22:13 b -rw-r--r-- 1 srk staff 0 Nov 12 22:13 a -rw-r--r-- 1 srk staff 0 Nov 12 22:13 d $ ls -l | 'awk $5==0{print "rm " $9}' | sh $ ls -l | 'awk $5==0{print "rm " $9}' | sh -x (tracing on) ------------------------------------------------------------------------ PROBLEM: You wish to number a file but skipping headers etc. (Why number lines? Useful when you wish to do a complicated merge+sort). ------------------------------------------------------------------------ $ cat > Rabbits %Rabbit_Name Rabbit_Index Parvi 10 Laxmi 5 Tubby 8 Padma 6 Rusty 6 cntrl D $ nl -b p"^[^%]" Rabbits %Rabbit_Name Rabbit_Index 1 Parvi 10 2 Laxmi 5 3 Tubby 8 4 Padma 6 5 Rusty 6 #Note that what follows after "p" is a regular expression. Note the #regular expression. (While at it, the expression "[^]" is not only #not what you think(!) but also makes no sense. [Worth pondering]. ------------------------------------------------------------------------ PROBLEM: Many data files come up with header lines. You want to proces the data but skip the header lines. The header lines are are usually identified by a distinct starting character or characters (e.g. "%" or "#"). ------------------------------------------------------------------------ $ cat Rabbits %Rabbit_Name Rabbit_Index Parvi 10 Laxmi 5 Tubby 8 Padma 6 Rusty 6 #Below only data lines are piped to AnalysisProgam #sed, grep, awk can use complex regular expressions #tail requires you to know and specify number of header lines $ sed '/^%/d' Rabbits | AnalysisProgram #delete all lines with % as first character $ sed -n '/^%/!p' Rabbits | AnalysisProgram #also possible using two negatives $ grep -v '%' Rabiits | AnalysisProgram #pass through lines which do not have % (anywhere) in the line $ awk '!/^%/' Rabbits | AnalysisProgram $ tail -n +2 Rabbits | AnalysisProgram # normal usage is $tail -n 5 Rabbits (last 5 lines) # GNU when the number is explicitly "+" then counting is from top # Thus $tail -n +2 file means start at the second line