Sponsored Content
Top Forums Shell Programming and Scripting Incrementing parts of ten digits number by parts Post 302861979 by Akshay Hegde on Thursday 10th of October 2013 03:10:26 AM
Old 10-10-2013
Whether you want like this

Code:
$ cat file
2013113098

Code:
$ cat serial.sh

  awk '

BEGIN{
         OFS="\t"
         printf RS OFS "Enter Year till which you want to generate serial number : "
         getline stop < "-"
         printf OFS "Enter Output Filname :  "
         getline out < "-" 
         nonleap = "31,28,31,30,31,30,31,31,30,31,30,31"
         leap     = "31,29,31,30,31,30,31,31,30,31,30,31"
         split(nonleap,NLP,",")
         split(leap,LP,",")
         if(!stop){printf RS "\t" "No User Input...Exiting" RS RS;exit }
     }

function serial(start,m,d,y){
                                   for(s=start;s<=100;s++)    
                                               if(out){
                                                       print y sprintf("%.2d",m) sprintf("%.2d",d) sprintf("%.3d",s) >out
                                                      } 
                                              else
                                                     {
                                                        print y sprintf("%.2d",m) sprintf("%.2d",d) sprintf("%.3d",s)
                                                     }
                            }

    {
        ser=substr($1,8,10)
        day=substr($1,7,2)
        mon=substr($1,5,2)        
        year=substr($1,0,4)

        if(stop~/[A-Za-z]/){print "Year should be Integer...Exiting" RS;exit}
        if(stop%1!=0){print "Year cannot be float...Exiting" RS;exit}
        if(stop<year){print "Year should be Equal or Greater than  Existing Serial Number...Exiting" RS;exit}

        f=1
        for(y=year;y<=stop;y++){
                mon=(f==1)?mon:1
                
        f=0
                g=1        
                for(m=mon;m<=12;m++)
                    {
                        dend=((y%4==0) || (y%100==0) || (y%400==0))?LP[m]:NLP[m]
                        day=(g==1)?day:1
                        ser=(g==1)?ser:0
                        for(day=day;day<=dend;day++){serial(ser,m,day,y)}
                g=0
                    }                
                                 }
            
     }' file

Resulting

Code:
$ sh serial.sh

  Enter Year till which you want to generate serial number : 2013
  Enter Output Filname :  test.txt

20131130098
20131130099
20131130100
20131201000
20131201001
20131201002
20131201003
20131201004
20131201005
20131201006

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cksum parts of a file

Every time we build an executable the date and time are put into the file, I need to run checksum on just the working lines.(IE, no header files) Is this even possible, if so how would I go about it? I am using a HP-UX server any help you can give me will be greatly appreciated. Thanks (6 Replies)
Discussion started by: crazykelso
6 Replies

2. Shell Programming and Scripting

getting parts of a file

Hello, I'm trying to retreive certain bits of info from a file. the file contains a list like this info1:info2:info3:info4 info1:info2:info3:info4 info1:info2:info3:info4 info1:info2:info3:info4 how do i pick out only info2 or only info3 without the others? Thanks (11 Replies)
Discussion started by: bebop1111116
11 Replies

3. Shell Programming and Scripting

Extracting parts of a file.

Hello, I have a XML file as below and i would like to extract all the lines between <JOB & </JOB> for every such occurance. The number of lines between them is not fixed. Anyways to do this awk? ============ <JOB APR="1" AUG="1" DEC="1" FEB="1" JAN="1" JUL="1" JUN="1" MAR="1" MAY="1"... (3 Replies)
Discussion started by: srivat79
3 Replies

4. Shell Programming and Scripting

[ask]break line number into several parts

hlow all, i have file with wc -l file.txt is 3412112 line number so I want to break these files into several parts with assumsi line 1-1000000 will be create part1.txt and 1000001-2000000 will create part2.txt and 2000001-3000000 will create part3.txt and 3000001-3412112 will create... (5 Replies)
Discussion started by: zvtral
5 Replies

5. Shell Programming and Scripting

Parts is parts, but all together ...

I understand the individual pieces of the following (with one exception ..), but how does it all work as one? find ${HOME}/reports/ -name surveyresult*.txt -exec ls -1 {} \; | /usr/xpg4/bin/grep -E \ "${HOME}/reports/surveyresult{14,14}.txt" | sort > ${ResultsFileList} Find all files like... (1 Reply)
Discussion started by: jdorn001
1 Replies

6. Shell Programming and Scripting

Extract Parts of File

Hello All, I have a file like this Define schema flat_file_schema ( a varchar(20) ,b varchar(30) ,c varchar(40) ); (Insert into table ( a ,b ,c ) values ( 1 ,2 ,3 ); (4 Replies)
Discussion started by: nnani
4 Replies

7. Shell Programming and Scripting

Combine two parts of a file

Hello All, I have a file like this APPLY ( 'INSERT INTO brdcst_media_cntnt ( cntnt_id ,brdcst_media_cntnt_cd ,cntnt_prvdr_cd ,data_src_type_cd ,cntnt_titl_nm ,cntnt_desc ,batch_dt ,batch_id ) VALUES ( :cntnt_id (3 Replies)
Discussion started by: nnani
3 Replies

8. Shell Programming and Scripting

Getting various parts from the log

I am dealing with some app log, see example below: 22:16:13.601 ClientSession(905)--Connection(5)--SELECT GETDATE() 22:16:13.632 ClientSession(158)--Connection(5)--SELECT 1 22:16:13.632 ClientSession(848)--Connection(6735)--SELECT 1 So far I needed to collect certain column from it, such as... (3 Replies)
Discussion started by: migurus
3 Replies

9. Shell Programming and Scripting

How to get first four parts of the string?

I have the string: XXXX.YYYY_ZZZ.20180724.01.txt I need to get rid of .txt and get full four parts XXXX.YYYY_ZZZ.20180724.01 I did: CTL=`echo XXXX.YYYY_ZZZ.20180724.01.txt | rev | cut -d"." -f4 | rev` But got only YYYY_ZZZ What should I do to get all four parts of that... (4 Replies)
Discussion started by: digioleg54
4 Replies
Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSuUser(Contributed Perl DocPerl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr(3pm)

NAME
Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr - Use 4-argument "substr" instead of writing "substr($foo, 2, 6) = $bar". AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
Conway discourages the use of "substr()" as an lvalue, instead recommending that the 4-argument version of "substr()" be used instead. substr($something, 1, 2) = $newvalue; # not ok substr($something, 1, 2, $newvalue); # ok The four-argument form of "substr()" was introduced in Perl 5.005. This policy does not report violations on code which explicitly specifies an earlier version of Perl (e.g. "use 5.004;"). CONFIGURATION
This Policy is not configurable except for the standard options. SEE ALSO
"substr" in perlfunc (or "perldoc -f substr"). "4th argument to substr" in perl5005delta AUTHOR
Graham TerMarsch <graham@howlingfrog.com> COPYRIGHT
Copyright (c) 2005-2011 Graham TerMarsch. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-06-07 Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr(3pm)
All times are GMT -4. The time now is 05:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy