I have the below script written.#!/bin/bashread -p Enter your SR number :  SRecho -e $SR\t$(date +%Y-%m-%d) >> /tmp/cases.txtawk 'BEGIN{printf(%-5s%-20s%-20s\n,#,Case Number,Date Opened)}{printf(%-5s%-20s%-20s\n,NR,$1,$2,$3)}' /tmp/cases.txtThe output of this in cases.txt file is[root@centOS ~]# cat /tmp/cases.txt1234567890      2017-03-242345678901      2017-03-24But the output of the script is:#    Case Number         Date Opened1    1234567890          2017-03-242    2345678901          2017-03-24If I try appending the awk output to cases.txt file, then it prints the column names everytime I run the script. My goal is, this script will be meant to keep a track of all incoming cases. The script will be run everytime a new case is opened. And it updates the cases.txt file. I would like to have the cases.txt file to have # Case Number and Date opened columns, where # increments every time a new value comes in. This partially works with the above script, but not the way I want it. Any help please? Thanks
Appending column to a dynamically changing / updating text
shell
f='/tmp/cases.txt'[ -s $f ] || printf '%s\t%s\t%s\n' '#' 'Case Number' 'Date Opened' > $fn=$(wc -l < $f)read -p Enter your SR number:  SRprintf '%d\t%d\t%s\n' $n $SR $(date) >> $f