In my program I’m trying to set up column headers for a file that I will be adding to throughout the script.
The line I use to create my headers is:
printf '%-10s' "csci" "csc" "Line #" "File Name" > "$1 3.txt"
This creates the headers just like I want, but when I go to add the next line it’s added to the end of this line instead of the next one.
I’ve been trying to put a newline in the header creation line so the next line that gets added will be the empty line but all of my attempts to add a newline has gotten strange results (or ones I just don’t want).
I’ve tried adding the \n like this: '%-10s\n', but this only makes my headers show up on separate lines (which I expected, but had to try this anyway).
I then tried: printf '%-10s' "csci" "csc" "Line #" "File Name" "\n"> "$1 3.txt", but this only printed out the \n as is without actually giving me a newline.
So, if my question isn’t obvious by now, how can I get a newline in there?
either add an
echoorprintfstatement after you print the columns, so that a new line is added:or define the whole line for
printfand add the\non the end:on
Bashthis should work too, though it appends some whitespace on the end of the new line: