3

Im trying to print like below

2333 k4k3 34kk 34r4
233k 2344 234l llll

with command

printf "%04d \n" "1111" "1123" "3333" "3333"  

but its breaks it. what I want to happen is all 4 values will be in single line and then add new line again.

1 Answer 1

1

The C style printf in bash expects each format specifier and an associated argument to be provided. For example

printf "Surname: %s Name: %s\n" "foo" "bar"

So you need to provide the specifiers for each of the arguments needed, something like

printf "%04d %04d %04d %04d\n" "1111" "1123" "3333" "3333"

(or) if you want to treat the entire set of words as a single string literal, you just need to use a single string format specifier. Notice below the quotes covering the entire set of arguments as one.

printf "%s \n" "1111 1123 3333 3333"

See The printf command in bash for more options and help articles.

Sign up to request clarification or add additional context in comments.

1 Comment

works fine. I guess it needs to set identifier for every argument. thanks lnian

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.