Ask a Question related to UNIX Programming, Design and Development.
-
Arto V. Viitanen #1
Re: scripting question Help
>>>>> "Matt" == Matt P <m_prorok@hotmail.com> writes:
Matt> I'm new to UNIX programming, and have been asked to write a script
Matt> that writes the name and number of lines in a file to a new file. The
Matt> part I'm having trouble with is the format; the # of lines has to be
Matt> 12 chars and right- justified. IE ' 238562'. Here's what I have so
Matt> far:
Matt> echo $filename `cat $filename | wc -l` >> $new_file
Matt> Which writes the filename and # of lines. Does anybody have an idea
Matt> of how to do the formating?
If your system has printf(1) command, you could
printf '%s%12d\n' $filename `cat $filename | wc -l` >> $new_file
If not, try awk or something similar
--
Arto V. Viitanen [email]av@cs.uta.fi[/email]
University of Tampere, Department of Computer and Information Sciences
Tampere, Finland [url]http://www.cs.uta.fi/~av/[/url]
Arto V. Viitanen Guest
-
Sprite Scripting question
I have a project with a large number of sprites that are generated using makeScriptedSprite in DirectorMX '04. As they appear on the stage, if any... -
basic scripting question
I have a couple of TextInput fields, and when you fill them out and hit a "submit" button, it saves that data as an item in a dataSet component. like... -
scripting question
Does anyone have any idea what kind of script has been used on the buttons on this site to give the bouncing effect?... -
Freehand 10 scripting question
What I would like to find or make is a script that will Import or Place an existing Freehand file into a Freehand 10 template and then export it as... -
Scripting Question -- Limiting Form Input
Hi, See attached code. This will do the trick and hopefully is what your looking for. Regards, Dan. <script> function checkValue(theId) { -
Frank Schmitt #2
Re: scripting question Help
[email]m_prorok@hotmail.com[/email] (Matt P) writes:
use printf(), which is available at least in ruby and perl.> I'm new to UNIX programming, and have been asked to write a script
> that writes the name and number of lines in a file to a new file. The
> part I'm having trouble with is the format; the # of lines has to be
> 12 chars and right- justified. IE ' 238562'. Here's what I have
> so far:
>
> echo $filename `cat $filename | wc -l` >> $new_file
>
> Which writes the filename and # of lines. Does anybody have an idea
> of how to do the formating?
ruby example:
#!/usr/bin/ruby
ARGV.each {|file|
len = `wc -l #{file}`
printf("%s %12i\n",file,len.to_i)
}
or, in one line:
ruby -e 'ARGV.each {|file| len = `wc -l #{file}`; printf("%s %12i\n",file,len.to_i)}'
For description of the printf() format specifiers, see man printf
HTH & kind regards
frank
--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frank DOT schmitt AT 4sc DOT com
Frank Schmitt Guest



Reply With Quote

