Using shell script,I want to count the csv file records (minus the header) and append the count to the same file in a new row.I also want to rename the file once the count
I have an input file mtest.csv like this
IP Header,Process Header,Device Header,ID Header
TestIP1,TestProcess2,TestDevice1,TestID1
TestIP2,TestProcess2,TestDevice2
TestIP3,TestProcess3,TestDevice3,TestID3
Sample output should look like this and the file should be renamed to mtest1.csv :
IP Header,Process Header,Device Header,ID Header
TestIP1,TestProcess2,TestDevice1,TestID1
TestIP2,TestProcess2,TestDevice2
TestIP3,TestProcess3,TestDevice3,TestID3
TOTAL_RECORDS,3
So I am trying the count the number of values of rows minus the header and append it in the last row with comma delimtted value like (TOTAL_RECORDS,3)
I am trying like this
#!/bin/bash
count = `cat mtest.csv | wc -l`
final_records = count -1
echo "TOTAL_RECORDS",$(final_records) $mtest.csv > mtest1.csv
But this isn't working for me and overriding the whole file and not appending.Can someone please help.