Created
December 3, 2015 15:00
-
-
Save ysinc88/f916eda91f569ef9dcbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
datafile=$1 | |
ctr=0; | |
while read line | |
do | |
# counter to keep track of line number | |
ctr=$((ctr + 1)) | |
# skip header line for processing | |
if [[ $ctr -gt 1 ]]; | |
then | |
# create filename using date field present in record | |
vdate=${line%% *} | |
vday1=${vdate%%/*} | |
vday=`printf "%02d" $vday1` # day with padding 0 | |
vyear=${vdate##*/} # year | |
vfilename="$2-${vyear}${vday}.txt" # filname in YYYYMM.txt format | |
# check if file exists or not then put header record in it | |
if [ ! -f $vfilename ]; then | |
head -1 $datafile > $vfilename | |
fi | |
# put the record in that file | |
echo "$line" >> $vfilename | |
fi | |
done < $datafile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment