Sponsored Content
Top Forums UNIX for Beginners Questions & Answers UNIX replacing and incrementing number Post 303037486 by chamajid on Friday 2nd of August 2019 11:12:39 PM
Old 08-03-2019
UNIX replacing and incrementing number

Hi

I am unix newbie looking for a unix bash script that can make it easier to do my code work. we have a code number for each code block that we want to incrementally assign. We have 10000 of these and it is very laborious to do this one by one.

so what we want is start from the top of the file , look for '0000' or text below whatver number is in it. start Update with 0001 and next wherever there is number like '0000' and also has '.001' int he same line then the number repeats. .001 does not change. Example below.

Code:
l_code_number := (l_src||'0011')::num

l_code_number := (l_src||'0012')::num

l_code_number := (l_src||'0012'||'.001')::num

l_code_number := (l_src||'0013')::num

l_code_number := (l_src||'0014')::num

l_code_number := (l_src||'0014'||'.001')::num
.
..
...

If the number is more 9999 thats ok. but till 9999 it should have pad of 4 zeros 0000. Please help. no perl please. So when ever I run the script to a file, the output should have the numbers replaced inside the file or to the output file.

Last edited by Don Cragun; 08-03-2019 at 02:16 AM.. Reason: Add CODE and ICODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl + array and incrementing number

morning guys and gals, I am haveing a problem, a friend helped me out with this script but i dont know how to add incrementing number for each movie in movie.list. this is what i have so far. any assistance would be great. I have removed the GT and LT symbols so you can see what is going on... (5 Replies)
Discussion started by: Optimus_P
5 Replies

2. Shell Programming and Scripting

Replacing the first 0 with a number

Hi, Appreciate any help in advance ;-) There are some numbers between 0 and 1, 0 not included: .2500, .3333, .5000, .6666, .7500, 1.000 How to replace the first 0 ( after the dot ) with a number, say, if the number is 3: .2500 will be .2530 .5000 will be .5300 .7500 will be .7530 ... (3 Replies)
Discussion started by: wanttolearn
3 Replies

3. Shell Programming and Scripting

Replacing word and Incrementing

Hi I'm having difficulty in writing a script with searching a specified word using sed and replaces that word with numbers that is incremented I tried this: #!/bin/sh awk '{ for (i=2010; i<=NF; i++) sed 's/TBA/$i; }' filename.txt > outputfile.txt but it doesn't work. here is my desired... (1 Reply)
Discussion started by: sexyTrojan
1 Replies

4. Shell Programming and Scripting

Unix c-shell - replacing/incrementing values in columns?

2 21 1 12 3 123 4 1234 6 49 0 49 33 212 I need to replace/increment all the values in the 2nd column that correspond to 0 in the first column. so for 0 49 i would get 0 50 this can be done through: paste num4.txt... (14 Replies)
Discussion started by: audrey_flox
14 Replies

5. Shell Programming and Scripting

Replacing Port number Using Sed

Hi Im trying to replace http port value.However for some reason its not working.Can you guys take a look and hit me with suggestions please.Your help is much appreciated. echo "Enter Value" read ans sed -i "s/http-port = 80 /http-port = $ans/g" demo Note:demo is the filename ... (6 Replies)
Discussion started by: coolkid
6 Replies

6. Shell Programming and Scripting

Incrementing number in bash

I have the following code and getting the error ./raytrac.bash: line 231: ((: 0++: syntax error: operand expected (error token is "+") iarg = 0 iarg=0 narg=$# # Number of arguments passed. echo "narg = $narg" argsArr=("$@") # Set... (1 Reply)
Discussion started by: kristinu
1 Replies

7. UNIX for Dummies Questions & Answers

Incrementing the New File Version Number

Hello All, In the below script i am trying to check and list the file names, get the last file with highest version number and then increment the version number when i create another file. Example: file1 is COBANK_v1.xml and file2 i want to put it as COBANK_v2.xml, to achieve this i am using awk... (15 Replies)
Discussion started by: Ariean
15 Replies

8. Shell Programming and Scripting

Replacing string by incrementing number

Dear all Say I have a file as ! TICKET NBR : 234 !GSI : 102 ! 3100.2.112.1 11/06/2013 15:56:29 ! 3100.2.22.3 98 ! 3100.2.134.2 8 ! ! TICKET NBR : 1809 ! GSI : 102 ! 3100.2.112.1 11/06/2013 16:00:45 ! 3100.2.22.3 65 ! 3100.2.134.2 3 ! ! TICKET NBR : 587 ! GSI : 102 ! 3100.2.112.1... (3 Replies)
Discussion started by: OTNA
3 Replies

9. Shell Programming and Scripting

Incrementing parts of ten digits number by parts

I have number in file which contains date and serial number: 2013101000. The last two digits are serial number (00). So maximum of serial number is 100. After reaching 100 it becomes 00 with incrementing 10 which is day with max 31. after reaching 31 it becomes 00 and increments 10... (31 Replies)
Discussion started by: Natalie
31 Replies

10. UNIX for Beginners Questions & Answers

Incrementing the New File Version Number

Hi, This is my first post here. I am using cygwin on Windows 7. I am starting with a data file with filename "name_1.ext", like "20180831_snapgenotypes_1.csv". The "_1" before ".ext" is a version number. Integers (0-99) are sufficient. They don't have to be like "1.0.0". The filename may... (2 Replies)
Discussion started by: minimalist
2 Replies
adjtime(2)							System Calls Manual							adjtime(2)

Name
       adjtime - correct the time to allow synchronization of the system clock

Syntax
       #include <sys/time.h>

       adjtime(delta, olddelta)
       struct timeval *delta;
       struct timeval *olddelta;

Description
       The  system  call  changes the system time, as returned by moving it backward or forward by the number of microseconds corresponding to the
       timeval delta.

       The time is maintained by incrementing it with a machine-dependent tick every clock interrupt.  If delta is negative, the clock	is  slowed
       down  by  incrementing  it  in smaller ticks until the correction is made.  If delta is positive, a larger tick is used.  Thus, the time is
       always a monotonically increasing function.  A time correction from an earlier call to may not be finished when is called again.   If  old-
       delta  is  nonzero, then the structure pointed to will contain, upon return, the number of microseconds still to be corrected from the ear-
       lier call.

       This call can be used in time servers that synchronize the clocks of computers in a local area network.	Such time servers would slow  down
       the clocks of some machines and speed up the clocks of others to bring them to the average network time.

       The call is restricted to the superuser.

Note
       Time is incremented in 3906-microsecond (us) ticks on RISC and 10000 us ticks on VAX.  When is called with a delta less than 1 second, time
       is incremented according to the following table until the time is corrected:

       -------------------------------------------
		Default     Fast	Slow
       System	Increment   Increment	Increment
       -------------------------------------------
       RISC	3906 us     3921 us	3891 us
       VAX	10000 us    10001 us	9999 us
       -------------------------------------------

Return Values
       A return value of 0 indicates that the call succeeded.  A return value of -1 indicates that an error occurred, and in this  case  an  error
       code is stored in the global variable errno.

Diagnostics
       The following error codes may be set in errno:

       [EFAULT]       An argument points outside the process's allocated address space.

       [EPERM]	      The process's effective user ID is not that of the super-user.

See Also
       date(1), gettimeofday(2)

																	adjtime(2)
All times are GMT -4. The time now is 08:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy