printf “columns” and newline

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 echo or printf statement after you print the columns, so that a new line is added:

(printf '%-10s' "csci" "csc" "Line #" "File Name"; echo) > "$1 3.txt"
# or
(printf '%-10s' "csci" "csc" "Line #" "File Name"; printf '\n') > "$1 3.txt"

or define the whole line for printf and add the \n on the end:

printf '%-10s %-10s %-10s %-10s\n' "csci" "csc" "Line #" "File Name" > "$1 3.txt"

on Bash this should work too, though it appends some whitespace on the end of the new line:

printf '%-10s' "csci" "csc" "Line #" "File Name" $'\n' > "$1 3.txt"

Need Your Help

Url.Action route config style path

I would like to create a Url.Action link that redirects to a page with the format

Regex password validation using JavaScript

javascript jquery regex validation

I need to validate (and confirm) a new password on a site. There are criteria I need to test for, and I'm looking for the best method to do so, using jQuery.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.