LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-07-2004, 10:38 AM   #1
mhjones
LQ Newbie
 
Registered: Jun 2004
Posts: 1

Rep: Reputation: 0
Formatted Strings in Script File


I'm looking for functionallity resembling 'sprintf' in a Linux Shell Script. I want to build a new strings which increament from 0-whatever. I want the output to look like the following:

blabla_000.txt
blabla_001.txt
blabla_002.txt

As you can see, I can't just insert the variable into the string. It also needs to be formated. I need something like '%03d' in sprintf.

Thanks,

Matt
 
Old 06-07-2004, 10:54 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
use printf try something like this:

Code:
let filecount=0
let filecount=filecount+1
filename=`printf "%s%04d" "blabla" $filecount`
 
  


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
how to add numbers in a formatted file via a bash script? zero79 Linux - General 8 12-24-2010 05:48 PM
bash script help (arrays and strings from files) nkoplm Programming 14 12-02-2005 09:50 AM
script to exclude strings... NiallC Programming 10 03-28-2005 06:46 PM
Creating Multiple user accounts from a formatted file collern2 Programming 2 03-09-2005 09:15 PM
Help with a script (question on strings) wswartz Linux - General 3 07-11-2004 08:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:45 AM.

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