My goal is to create a bash file that counts the lines in about 16 files, each having a date, and send the following (16 times) to a .csv file.
So far, I've managed to count the lines, but the .csv file is messy and needs to be trimmed and made suitable for csv: Ex:
1500 FNB_EgTrans_20171004.txt
My goal is to make it look like this: 1500,EgTrans,20171004
Can someone explain to me why my below method of using tr with cat isn't working as expected? Thanks.
cat $reccnt | tr ' FNB_' ',' | tr '201' ',' < $reccnt
Below is the entire code in case elaboration is necessary:
#!/bin/bash
cd /ssinput/NY_AML/
reccnt=ny_row_count.csv
activedate='100000'
if [ -e $reccnt ];
then
rm $reccnt
else
touch $reccnt
chmod 755 $reccnt
fi
ls -t1 FNB*|head -15 |cut -c 13- > ny_activedate.txt #second tail or cut?
activedate=$(cat ny_activedate.txt)
echo $activedate
wc -l *$activedate | head -16 > $reccnt
reccnt="${reccnt##*( )}"
cat $reccnt | tr 'FNB' ',' | tr '201' ',' < $reccnt`