I am learning AWK by trying out examples whenever I need a specific conversion. I would like to edit the 'before.txt' so that all the missing data points between 140-150 are added and shown as 0.
You do something in the BEGIN section, before the before.txt is processed.
And then you do nothing in the main section (where it's too late anyway).
The solution is to process the file in the main section and store it into variables (An array that is addressed by the $1 values), and then process/print in the END section. Like RudiC did.
The following is multi-line for readability (at least for me), and does not have the NR==FNR {...; next} overhead (that takes the first given file, where the following code will take the next file(s) - but here is only one file).
It prints with an explicit if - else, like you did; compare with RudiC's implicit if!
These 2 Users Gave Thanks to MadeInGermany For This Post:
I am learning AWK by trying out examples whenever I need a specific conversion. I would like to edit the 'before.txt' so that all the missing data points between 140-150 are added and shown as 0.
before.txt
145 2
148 13
149 17
to below,
140 0
141 0
142 0
143 0
144 0
145 2
146 0
147 0
148 13
149 17
150 0
And here is what I tried so far.
Any help would be great
Hello numareica,
Welcomes to forums, special thanks for using the code tags. Could you please try following and let me know if this helps. 1st: If you need to have maximum number till 150 only from 140 then following may help you.
Let's say following is the Input_file:
Output will be as follows. EDIT: Adding 1st solution's non-one liner form now. 2nd: If you need to run the commands till the last maximum number starting from 140 then following may help you in same. But in case maximum number is lesser than value of 150 then it will take care of printing the values till 150.
Let's say following is the Input_file:
Then following is the code for above:
Output will be as follows then. EDIT: Adding a non-one liner form of 2nd solution now.
Thanks,
R. Singh
Last edited by RavinderSingh13; 01-14-2016 at 09:59 AM..
Reason: Added non one-liner forms of both the solutions now.
This User Gave Thanks to RavinderSingh13 For This Post:
.
.
.
and does not have the NR==FNR {...; next} overhead (that takes the first given file, where the following code will take the next file(s) - but here is only one file).
.
.
.
Absolutely right - I started "the usual way" and overlooked the "one file only" ... rats!
HI Everyone,
I have below source file
AAA|NAME1|ADDRESS1|300.20
BBB|NAME2|ADDRESS2|400.31
CCC|NAME3|ADDRESS3|300.34
I have requirement where I need to sum up fourth field in above fixed width pipe delimited flat file. When I use below code, it gives me value 1001.00
But I am expecting... (1 Reply)
Dear all,
I am kindly seeking assistance on the following issue.
I am working with data that is sampled every 0.05 hours (that is 3 minutes intervals) here is a sample data from the file
5.00000 15.5030
5.05000 15.6680
5.10000 16.0100
5.15000 16.3450
5.20000 16.7120
5.25000... (4 Replies)
Hi
Please I need some help, I have system running solaris 10, with a file system at 100%:
df -h /nikira
Filesystem size used avail capacity Mounted on
/dev/dsk/c5t500A09818DE3E799d0s0
226G 223G 0K 100% /nikira
but when I look inside to... (17 Replies)
Hi,
I have to text files that I want to merge by the first column. The values in the first column pretty much match for the first part. However there are some values that are present in column 1 and not present in column 2 or vice versa. For such values I would like to substitute X for the... (9 Replies)
Hello all,
I have a file which is tab separated like that:
PHE_205_A TIP_127_W ARG_150_B
MET_1150_A TIP_12_W VAL_11_B
GLU_60_A TIP_130_W ARG_143_B
LEU_1033_A TIP_203_W ARG_14_B
SER_1092_A TIP_203_W
THR_1090_A TIP_203_W
SER_1092_A TIP_25_W ... (6 Replies)
Hi all,
I have a template form to fill in for quite a number of files and I want to automate the filling-in process. the concept seemed to be simple but i cant get it work. the template form is a text file containing the information below:
File Name:
Date Created:
Contents:
I need to... (4 Replies)
Hi Guys,
I have EMC Storage and from this storage I have maped lun5 to Sun Solaris server and I have created on this lun mount point with name /application
I have anothere Sun Solaris server and I'll colne lun5 to lun10 from storage level so the data of lun5 will be in lun10
how to... (6 Replies)
Hi,
I wanted to extract the data from a particular comma from each line.
My file contains some 10000 lines and each lines are separated by commas. There are 60 fields which are separated by 59 commas.
I wanted to show the data which are there after the 49th comma from each line.
For... (2 Replies)
Hi all,
I have a file that contains about 1000 rows and 800 columns. Nearly every row has 800 columns but some DONT. I want to extend the rows that dont have values with NA's. Here is an example:
my file
bob 2 4 5 6 8 9 4 5
tar 2 4 5 4 3 2 9 1
bro 3 5 3 4
yar 2 ... (7 Replies)