Help Please...........


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help Please...........
# 1  
Old 07-16-2007
Help Please...........

I have a file (say file.txt) with following entry (there are other entries in the file too)
F07812000166220070627012300 X
I have divided the string and assigned it to different variables in a script -file.script (I require these variables for certain validations). Eg : -
a=F07812
b=0001662
c=20070627
d=012300
e=
f=X

what i have to do is and add one to variable b (throught the script) and insert it in the begining of file.txt.
So i should get the following entries in the file : -

F07812000166320070627012300 X
F07812000166220070627012300 X

Can anyone help me with this please....???
# 2  
Old 07-16-2007
I got how to do it...
Smilie
Thanks !!!
# 3  
Old 07-16-2007
Code:
FILE=/home/dir/ss

cat $FILE | cut -d"=" -f2 >/home/dir/ss/sss

for i in `cat /home/dir/ss/sss`
do
echo -n $i
done

You can try above code
# 4  
Old 07-16-2007
Code:
mOrigLine=$a$b$c$d$e$f
b=$b+1
echo $a$b$c$d$e$f
echo $mOrigLine

# 5  
Old 07-16-2007
Quote:
Originally Posted by Shell_Life
Code:
mOrigLine=$a$b$c$d$e$f
b=$b+1
echo $a$b$c$d$e$f
echo $mOrigLine

if u say

b=$b+1 wont it be a string concat..?

and if u say b=`expr $b + 1 ` then if b=0000012 it print back as 13

how to retain the zeros
# 6  
Old 07-16-2007
Pbsrinivas,
Quote:
b=$b+1 wont it be a string concat..?
No. The OP says he wants to add one to the 'b' variable.
Thus the assumption is that 'b' is defined as integer:
Code:
typeset -i b

Quote:
how to retain the zeros
See the following code:
Code:
typeset -i b
typeset -Z7 bOut
b=123
bOut=$b
echo "b = "$b" bOut = "$bOut

Thanks for asking, Pbsrinivas. Smilie
# 7  
Old 07-16-2007
Quote:
typeset -i b
typeset -Z7 bOut
b=123
bOut=$b
echo "b = "$b" bOut = "$bOut
this gives the following error

./a: line 2: typeset: -Z: invalid option
typeset: usage: typeset [-afFirtx] [-p] name[=value] ...
b = 123 bOut = 123

I am using AIX... Is that an issue..


And if we come to the oraginal post

i think
a=F07812
b=0001662
c=20070627
d=012300
e=
f=X

he has show as a b and c but if u just want to do like this...

F07812000166320070627012300 X to
F07812000166220070627012300 X


add one the number in BOLD feild?? how can we do that...

that is ... to the digits form 7 to 13 fields??
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question