Shell Script To Write Odd and Even Line To Respective Files

in Categories Academic, Decision Making, File-management last updated September 17, 2008


Share this on:

2 comment

  1. awk ‘NR % 2 {print > “odd”} ! (NR % 2) {print > “even”}’ inputfile
    This will split input file into files “even” and “odd”
    Or is this more about bash than invoking utilities? And what utilities are allowed then?
    /usr/bin/[ is not a builtin…


  2. ODDRE="^ [0-9]*[13579]"
    cat -n $1 | grep "$ODDRE" | cut -b 8- > oddfile.$$
    cat -n $1 | grep -v "$ODDRE" | cut -b 8- > evenfile.$$

    Have a question? Post it on our forum!