I have the following script
awk '{printf "%s", $1"-"$2", "}' $a >> positions;
where $a stores the name of the file. I am actually writing multiple column values into one row. However, I would like to print a comma only if I am not on the last line.
I would do it by finding the number of lines before running the script, e.g. with coreutils and bash:
If your file only has 2 columns, the following coreutils alternative also works. Example data:
Output:
Now replacing tabs with newlines,
pasteeasily assembles the date into the desired format:Output: