Part of LOM

This blog is part of web activities of the Laboratory of Organic Materials (LOM) of the Institute of Solid State Physics of the University of Latvia.

Friday, June 30, 2017

Small bash code to split batch .OUT file in parts

This is trivial, but in any case…

Batch jobs output files can grow big, which causes problems for reading them. This code splits them in smaller chunks by selected number of jobs done to be read automatically later. Chunk filenames are derived from the initial file name by adding "_L1", "_L2", etc. before file extension.

$ ./asplout split-by-how-many filename
112230: Normal termination of Gaussian 09 at Thu Apr 27 00:30:13 2017.
391832: Normal termination of Gaussian 09 at Fri May 5 03:24:39 2017.
454985: Normal termination of Gaussian 09 at Fri May 5 20:41:34 2017.
531521: Normal termination of Gaussian 09 at Sat May 6 17:43:29 2017.
629500: Normal termination of Gaussian 09 at Mon May 8 02:16:22 2017.
682260: Normal termination of Gaussian 09 at Mon May 8 16:48:18 2017.
773911: Normal termination of Gaussian 09 at Tue May 9 19:28:10 2017.


#!/bin/bash
[ "$1" == "-h" ] && echo "First argument: # of jobs in single split. Second argument: .OUT file name." && exit 0
irk=0; pesk=0
cp $2 bakabaka.out
while read menschutk; do ((irk++)); [ $((irk/$1*$1)) -eq $irk ] && { moose=$(echo $menschutk | cut -d : -f 1); sed -n '1,'$((moose-pesk))'p' $2 > ${2%.out}_L$((irk/$1)).out && echo $menschutk; sed -i '1,'$((moose-pesk))'d' $2; pesk=$moose; }; done < <(grep -n 'Normal termination' bakabaka.out)

rm bakabaka.out

No comments:

Post a Comment