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.
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.
We like to see some effort from our new members, before helping.
But since you are new, and this is your first post, here is one possible attempt :
This is GNU awk GNU Awk 4.2.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.1.2)
If you are satisfied with result, redirect it to output file.
Please, in future requests, provide some of your code / attempts first.
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.
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.
I am afraid that from your description I have no idea what you are trying to do.
You show us sample input that has absolutely no occurrences of the string '0000' and you do not show us the output that you want to be produced from that input.
You say that changed numbers less than 9999 should have a pad of four zeroes, but none of your samples do that. They are padded to four digits, but none of them have four leading zeroes as requested.
Please clearly explain what you are trying to do, show us sample input that shows us the various things you are trying to do (in CODE tags), and show us the corresponding output that you hope to produce from that sample input.
If you have a bunch of input files, is each file supposed to modified to change '0000' to sequential values starting at one or are the numbers to be assigned sequentially such that the same number is never assigned in more than one output file?
Where are the files that are to be used as input files? If there are files in that directory that are not to be modified, how is your script supposed to know which files are to be processed? Where are the output files to be placed?
Peasant, I did not have a clue on how to start, had a a mental block so could not do an attempt. I am searching for a script that does atleast some part of it but whenever i change it i get errors and just left me frustrated. Hence i made this post. I will try this and see if it works. thank you for your attempt. I will add a post once i give it a shot.
Don,
Looks like I messed up. Sorry about missing code tags. I will put extra effort to follow the rules. I would recommend if you can put some validation so it does not allow any one posting without code tags. But you will not see that from me every again hopefully. I will put in the explanation with more information.
we have one file that has our sql code that has code numbers to identify if there is an error we can find it with the code number. those code number should should start with
and have code section and then
and so on, where ever there is a .
, ""the current number" repeats.
It looks like this. I have changed it start from 1. so Basically I want to update what ever is the number in the
. I have already built up the file by copying pasting code blocks but not updated the numbers 1 by 1. it is a 10000 code blocks file. and it is very laborious to change it one by one to 10000
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)
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)
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)
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)
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)
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)
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)
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)
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)