Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
unix script help
Name: jds Date: March 8, 2006 at 16:17:18 Pacific OS: windowsXP CPU/Ram: petium III/ram 256
Comment:
Hi, I am trying to process the file for next month (if this month is 03 then I'll need to look at 04 files) I use month = `date + %m` to get value of 03 for this month If I use month='expr $month + 1` it will give me 4 instead of 04. I then use month=`"0"$month` to covert it to 04. Also if use my way when it reach to >10 then I'll need to covert again. I would like to know is there any better way to to this?
I was trying to do like this: while [condition]; do something... #I want add if here like: month=`date +%m` month=`$month + 1` if ($month<10) month=`"0"$month if ($month=13) month=01 something... done
for some reason it doesn't work. anything wrong? Please advice. Thanks
Name: nails Date: March 8, 2006 at 20:25:15 Pacific
Reply:
Once you are done with all your arithmetic, use the external printf command (similiar to the "C" version of printf). If the number is only 1 digit it'll prepend a 0:
#!/bin/sh
m=9 m=`printf "%02d\n" $m` echo $m
n=11 n=`printf "%02d\n" $n` echo $n
0
Response Number 2
Name: Wolfbone Date: March 8, 2006 at 21:17:44 Pacific
Thank you all for the help. Nails' way works for me perfect unfortunately, my 'date' is not fully functioned so I can't use Wolfbone's way
Now I have another question: when I process next month month=`expr $month + 1` if $month=13 month=1 -- this one is not working. where I did wrong? it says:" 'if' unmatched" please advice.
Thanks
0
Response Number 4
Name: nails Date: March 9, 2006 at 22:26:30 Pacific
Reply:
You don't have the correct if syntax:
month=12 month=`expr $month + 1` if [ $month == 13 ] then month=1 fi echo $month
Summary: Im doing some unix scripting and would like to, based off a file input calculate date. What we have is what is called infile in the script it reads certain fields within this "infile" the infile is ju...
Summary: Hi All, I am relatively new to Unix scripting. I have to write a script based on below logic- Upon start, record the current date (CURRENT_DATE) while (current timestamp is less then or equal [CURRE...
Summary: I have refernce file with some data in it myfile: aaaa bbbb cccc dddd and I have to write a script in unix such that for the first time the script has to take first line as a variabe or as an input an...