[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

padding zeros to the no of recs from the file

Posted on 2009-04-22
7
Medium Priority
?
289 Views
Last Modified: 2012-05-06
echo '0000000 expr `wc -l < filename` -2 '|sed 's/.*\(.......\)$/99\1/'


I am trying to get count of recs from afilename and  subtract 2 from the count and padding zeros to the  count after subtraction  and append 99 in the start of the line


I am getting some error
0
Comment
Question by:sumanth_ora
7 Comments
 
LVL 16

Expert Comment

by:ai_ja_nai
ID: 24205786
I couldn't understand what you want.
Please, rewrite the procedure in a multi-line form with one step per line
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24205960
please elaborate
0
 

Author Comment

by:sumanth_ora
ID: 24207124
I like get the no of records(count) from a file then subtract 2 from that

ex:no of recs from a file =100
    subtract 100-2=98

I need to padded with zeros always lenth of the padded value should be  be 7 charecters

if value is 98 then 0000098
if values is 8 then 0000008
if values is 345 the 0000345

Finally am appending 99 in the front of the string

990000098
990000008
990000345

0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 16

Expert Comment

by:ai_ja_nai
ID: 24207479
I see. You should use a script (like the one attached, which takes a filename as input and prints the corresponding string)
#!/bin/bash
 
count=`cat $1|wc -l`;
count=$(($count - 2));
l2=`echo ${#count}`
for ((i=$l2;i<7;i+=1)); do
        count="0${count}"
done;
count="99${count}";
echo $count;

Open in new window

0
 

Author Comment

by:sumanth_ora
ID: 24207855
I was looking for single  line statement insted of programing

Jsut like this

echo '0000000 expr `wc -l < filename` -2 '|sed 's/.*\(.......\)$/99\1/'
0
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 24209257

printf "99%07d\n" $(eval expr "$(wc -l<filename) - 2")

0
 
LVL 16

Expert Comment

by:ai_ja_nai
ID: 24209390
What year are we in, forgive me? :)
Do we still have the limit of 32KB of physical memory? One line statements are difficult to mantain and to understand. I prefer extended scripts ;)

BTW, nice shot TinTin
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question