***************************************************************** Date: Thu, 19 Aug 2004 From: Marco Verzocchi awk '{print $2}' > input.txt | /home/mverzocc/binLinux/fastsum Useful for adding a column of floats. Goes through the input.txt file, reads the second column and using a little C program performs the sum. ****************************************************************** Date: Fri, 13 Aug 2004 20:28:00 -0500 (CDT) From: buehler cat input.txt | awk '{if ($12>10) print $0}' > output.txt It goes through input.txt line by line, checks if the number of events, $12 (12th column), is larger than 10 (for example), and if so prints out the entire line ($0) into output.txt. ****************************************************************** Date: Fri, 28 Nov 2003 06:40:48 +0100 (CET) From: Laurent Duflot If you want to know how many lines there are in a file, you can do wc -l myfile ****************************************************************** Date: Fri, 28 Nov 2003 13:48:34 -0600 From: Stilianos Kesisoglou Look at the following small piece of code (syntax is for sh/ksh/bash UNIX shells):   #!/bin/bash   #   Input file provided. Test if the file exists first. inFile='myData';    if [ -f ${inFile} ]; then echo "Input File Missing"; exit ; fi   #   Initialize index. idx=0;   #   Loop over the contents of the inFile and make outFiles. while [ ${idx} -lt $(wc -l < ${inFile}) ]; do awk 'BEGIN{X='$((2*${idx}))';Y='$((2*${idx}+3))'} {if (NR>=X && NR<=Y) print $0}' > outFile_${idx}   idx=$((${idx}+1))     done < ${inFile}   Your main interest is inside the "while" loop. If you look at the awk argument it is a concatenation of the following strings:       1)    'BEGIN{X='       2)    $((2*${idx}))       3)    ';Y='       4)    $((2*${idx}+3))       5)    '} {if (NR>=X && NR<=Y) print $0}'   Because the shell resolves any variable references BEFORE it handles the argument to awk, strings (2) and (4) are substituted by a number before the whole fixed string is made and passed to awk. So essentially awk takes as an input a fixed string BUT with numbers X and Y that change for every loop execution.       A general advise for shell script writing is to use the Bourne family (sh, ksh or bash shells). This family is by far superior in writing shell scripts than the C-Shell family. ****************************************************************** Date: Fri, 28 Nov 2003 14:33:27 -0600 From: Paul S. Russo Common text file manipulation patterns To append file 2 to file1 giving file3: $ cat file1 file2 > file3 To pipe all lines from file1 to the wc (word count) command: $ cat file1 | wc To get the first N lines of file1: $ head -N file1 or equivalently: $ head -n N file1 To get the rest of file1, skipping the first N lines: $ tail +N file1 To get the last N lines of file1: $ tail -N file1 To get only the lines from file1 that match a pattern: $ egrep 'pattern' file1 To get lines from file1 which *do not* match a pattern: $ egrep -v 'pattern' file1 To translate tabs to an equivalent number of spaces in file1: $ cat file1 | col -x To make it possible to search the output of the man command: $ man topic | col -bx | less To select columns 1, 5, 9, 10, and 11 from the output of the ls -l command: $ ls | tr -s ' ' | cut -d ' ' -f 1,5,9,10,11 where tr -s ' ' squeezes multiple spaces to just one, and cut -d ' ' -f 1,5,9,10,11 divides each line into columns delimited by the ' ' character and selects fields (columns) 1, 5, 9, 10, and 11 (attributes, size, name [including symlink]). To see the contents of your PATH environment variable more clearly: $ echo $PATH | tr ':' '\n' To sort file1: $ sort -o file1 file1 To sort the output of ls -l by size (column 5): $ ls -l | sort -b -n -k 5,5 If you know both file1 and file2 are almost the same but still different (like two directory listings that are supposed to contain the same files but don't quite): To find which lines are in file1 but not in file2: $ comm -23 file1 file2 To find which lines are in file2 but not in file1: $ comm -13 file1 file2 To find which lines are in both file1 and file2: $ comm -12 file1 file2 If the output of these commands is not making sense try: $ sort -u -o file1 file1 $ sort -u -o file2 file2 then use the comm command. ****************************************************************** Date: Thu, 27 Nov 2003 21:21:31 -0600 From: Stilianos Kesisoglou The following command takes the lines from X=10 to Y=17 (included lines X and Y) from the file "inFile" and places them on the file "outFile". cat inFile | awk 'BEGIN{X=10;Y=17} {if (NR>=X && NR<=Y) print $0}' > outFile ****************************************************************** Date: Thu, 11 Sep 2003 12:43:22 -0500 From: Peter Tamburello "I have text file containing an integer number in each line. Is there an easy way to get the sum of those numbers?" awk '{sum+=$1; print sum}' file.txt | tail -1