The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
cannot get logic for concatenation awk user_prady Shell Programming and Scripting 7 12-09-2007 11:09 PM
File Concatenation samit_9999 UNIX for Dummies Questions & Answers 3 11-21-2006 02:26 AM
string concatenation systemsb UNIX for Dummies Questions & Answers 7 04-04-2006 09:03 AM
Implementing Concatenation(cat) toughguy2handle High Level Programming 2 09-21-2005 11:10 PM
Concatenation videsh77 Shell Programming and Scripting 2 12-14-2004 02:13 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-04-2007
Registered User
 

Join Date: Apr 2007
Posts: 23
Concatenation

How can I do this:

date = 4 -----------> 04
Month= 3-----------> 03

I wish to make a varibale named Var1 which will hold the value of current date and month value as:

2 digits for date.
2 digits for month.

So finally var1 should hold value as 0403 --- MMDD
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-04-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
var1=$( printf "%02d%02d" $date $Month )
Reply With Quote
  #3 (permalink)  
Old 04-04-2007
Registered User
 

Join Date: Apr 2007
Posts: 23
But it is prompting syntax error...
Code:
$DB_Date=$(printf "%02d%02d", $date, $Month );
Reply With Quote
  #4 (permalink)  
Old 04-04-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Quote:
Originally Posted by Asteroid
But it is prompting syntax error...
Code:
$DB_Date=$(printf "%02d%02d", $date, $Month );
That is the syntax used in shell script.
Try this
Code:
$DB_Date=sprintf("%02d%02d", $date, $Month);
Reply With Quote
  #5 (permalink)  
Old 04-04-2007
Registered User
 

Join Date: Apr 2007
Posts: 23
Code:
$DB_Date=sprintf("%02d%02d", $date, $Month);
$DB_Date=printf("%02d%02d", $date, $Month);

I have previously tried the above....

But It gives out 0000 ...

Really I am lost how it could be possible in PERL.
Reply With Quote
  #6 (permalink)  
Old 04-04-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Can you show your full code?
Reply With Quote
  #7 (permalink)  
Old 04-04-2007
Registered User
 

Join Date: Apr 2007
Posts: 23
Code:
#!/bin/perl -w
use IO::Handle;

($day, $month, $year) = (localtime)[3,4,5];


$month=$month+1;
$year=$year+1700;
$DB_Date=printf("%02d%02d", $date, $Month);

open (dbfile, "/data1/scp/store/DB/0403/SCP_PP_SUBS.dat") or die "Couldn't get at THE FILE";

@data;
$credit;
$count =0;



          print "DB_Date:: $DB_Date \n\n";                       
          print "LESS then the 100 Credit $day/$month/$year\n\n";  
           print "-------------------------------------------\n";

 while (<dbfile>) 
 {
         ........................
         ..........................
         ............................
         ...........................

 Do some file parsing operation

}

print "Total Count: $count \n";
close dbfile;
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0