[GLP] Play With Shell

Two Efficient Methods for Line-by-Line File Processing in Shell Method 1: Using a File Descriptor Redirect stdout to a file descriptor (fd 4), then restore it after processing. This is slightly faster for large files. 1 2 3 4 5 6 7 8 9 10 11 12 13 function while_read_line_bottom_fd_out { >$OUTFILE exec 4<&1 exec 1>$OUTFILE while read LINE do echo "$LINE" : done < $INFILE exec 1<&4 exec 4>&- } Method 2: Without a File Descriptor Simpler and easier to maintain — appends each line directly to the output file. ...

June 7, 2020 · hyyfrank