Perl script to change the date in some scenario


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl script to change the date in some scenario
# 1  
Old 12-31-2012
Perl script to change the date in some scenario

Hi ,

I have file FSN.log which contains number 100. i have other Perl script when i run it , it ll increment this FSN.log value.

now my requirement is
when the count in FSN.log becomes 999, it should make the value to 100 again and Perl script to change the date or it should make the date field value as previous or something and it should remain the same..

anyone can help with this ?

Thanks
# 2  
Old 12-31-2012
Okay. Please show sample input and sample expected output.

What have you tried so far?
# 3  
Old 01-02-2013
#!/usr/bin/perl -w
Code:
# Print the value of the command line arguments
$FSNCount = $ARGV[2];
#print "Replacing all QQQ in $ARGV[0] - with $FSNCount in $ARGV[1]\n";
$DateField=`date +%Y%m%d`;
chomp ($DateField);
$TimeField=`date +%H%M`;
chomp ($TimeField);
open INPUTFILE, $ARGV[0] or die $!;
open OUTPUTFILE,">$ARGV[1]" or die $!;
# Read the input file line by line
while (<INPUTFILE>)
  {
    $_ =~ s/QQQ/$FSNCount/g;
    $_ =~ s/YYYYMMDD/$DateField/g;
    $_ =~ s/HHHH/$TimeField/g;
    print OUTPUTFILE $_;
  }
#while (<INPUTFILE>)
#  {
#  }
print "\t $DateField\n";
print "\t $TimeField";
close INPUTFILE;
close OUTPUTFILE;
~

This is wat i have tried

---------- Post updated at 04:51 PM ---------- Previous update was at 04:42 PM ----------

initially FSN count =100 and date value ll become current date but when FSNCOUNT = 999 , Date field should be changed to previous day s date and again FSN count should become 100...and the date value should be previous day only till it reach 999 again. so on
Code:
eg : FSN COUNT =100 , date= 20130102
      FSNCOUNT=101, date = 20130102
     ....
     ....
     FSN COUNT =999, date= 20130102 and FSN COUNT should become 100

and from next time date=20130101
so next time
Code:
FSNCOUNT=100, date = 20130101
....


Last edited by Scott; 01-02-2013 at 08:44 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Date format change from mm/dd/yyyy to yyyymmdd in comma seperate line in perl

Hi All, I have line ,A,FDRM0002,12/21/2017,,0.961751583,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, it contains date in mm/dd/yyyy format i want to change this to yyyymmdd format using perl. Use code tags, thanks. (8 Replies)
Discussion started by: vishal0746
8 Replies

2. Solaris

How to change the date automatically on script?

Hello Experts, There is a log file which has date stamp, I just wanted to change the date automatically on daily basis when it runs. Tried the below, but no luck. grep -i error /var/bv1to1_var/logs/bv03.bectondickinson.com/bvlog.out.`date +\%Y\%m\%d` | tee error_bv03.doc I would highly... (10 Replies)
Discussion started by: seenuvasan1985
10 Replies

3. Shell Programming and Scripting

Script to change date/time

Hi everybody! I need to perform a task with a script but I have no idea how to do it, I hope someone could help me: - on my linux pc I have many folders with movies, tv shows, toons, ecc. They are shared by a dlna server to my panasonic tv where I can browse and see them. The problem is that... (6 Replies)
Discussion started by: Torquemada
6 Replies

4. Shell Programming and Scripting

Script to change name of a file with date

I have a file that contains todays date(for ex- test_08/30/2013) Now I want a script which will run and change the name of the file and put yesterday's date (for ex- test_08/29/2013) Please help. ---------- Post updated at 04:40 AM ---------- Previous update was at 04:31 AM ---------- I... (2 Replies)
Discussion started by: sv0081493
2 Replies

5. Shell Programming and Scripting

Change date format in shell script

Plz help me To display date in the mm/dd/yyyy. Eg. if date is 28-09-2012 the output of the shell script should be date 09/28/2012. (1 Reply)
Discussion started by: shivasaini
1 Replies

6. Programming

date change shell script in java code

hi, I have a code to connect to a remote Linux server through windows using SSH, with host-name, username and password built in the code. I want to add a shell script in the code which should execute automatically without any user intervention. (as u know that date change requires you/us to be... (0 Replies)
Discussion started by: tarkan
0 Replies

7. Shell Programming and Scripting

How to Script This Scenario

hi all, i have to schedule an email containing the information about some orphan connections existing on the server depending upon the system date. the format of the info to be sent in email is : Process id username servername time when connection... (0 Replies)
Discussion started by: Priyanka S
0 Replies

8. Shell Programming and Scripting

help for change date format script

Someone can help me write a script for change date fromat from "Feb 4 18:44:03 2009" to 2009020418 ? from "Mar 17 16:44:03 2009" to 2009031716 ? (4 Replies)
Discussion started by: pccwtest
4 Replies

9. Shell Programming and Scripting

multipe instance scenario in perl

letz say that my file has 7 records with only one field. So my file has: 11111111 000000000000000 1111 aaaabbbccc 1111111222000000 aaaaaaaa zz All i need is: 1. when the field has a repetition of the same instance(a-z or 0-9), i would consideer it to be invalid.... (4 Replies)
Discussion started by: helengoldman
4 Replies

10. Shell Programming and Scripting

script to change the date format in a file

i have many files with date format of 6-9-2008 and i want a script that can change the format to 2008-06-09 Thanks (15 Replies)
Discussion started by: shehzad_m
15 Replies
Login or Register to Ask a Question