LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-03-2019, 04:07 AM   #16
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309

Quote:
Originally Posted by lleb View Post

Code:
for i in {0..6..1}	# {START...END...INCREMENT}
	do
		# echo "foo.${i}.TEST"&>>grab.txt
		printf 'foo.%02d'${i}'.TEST\n'&>>grab.txt
	done
Question though, why %02d and not %03d.
In this example you print a 2 digit number and $i. printf requires a format string and arguments. Here the argument is missing, so it is 0 always. That's why you have 00 always before $i.

From the other hand seq executed in a subshell, therefore it is much slower than any other solution.
 
1 members found this post helpful.
Old 02-03-2019, 06:14 PM   #17
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Original Poster
Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Quote:
Originally Posted by Beryllos View Post
Small correction about your comments:

in the format specifier '%03d'
d means the number is expressed in decimal (base 10)
3 is the minimum field width, normally whitespace-padded
0 signifies zero padding
Code:
$ printf '%d\n' "5"
5
$ printf '%3d\n' "5"
  5
$ printf '%03d\n' "5"
005
$
Thank you for the details on the comments. I have updated my code to make it simpler to repeat, edit down the line.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Fast disk, fast network, slow file transfer? JorgenK Linux - Server 1 02-26-2016 01:00 PM
FAST (Mega fast Mirror) SUSE 10 beta 4 download 1kyle SUSE / openSUSE 2 09-07-2005 10:13 AM
Slamd64 is FAST FAST !!! SML Slackware 10 05-03-2005 05:36 AM
KDE 3.4 Beta 1 - Fast, Fast, very nice linchat SUSE / openSUSE 0 01-25-2005 11:42 PM
internet fast-slow-fast-slow big_and_fat_guy Mandriva 5 10-11-2003 05:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration