Trying to pull records from a .DAT file but my results are blank. I think I have misunderstood how to use file management - record

So I am trying to pull the records from a file formatted as follows (The reason I am asking this, despite similar questions existing is because I am on a much more "beginner" level than those questions covered.)
ELF-CAL
6669
6434
6564
1032
1098
1829
2608
7322
2690
7061
1664
5769
ELF #16160
1082
3958
5272
2188
5618
3418
2302
2926
3338
1082
2024
4195
4083
ELF #13276
5581
3421
3403
4356
2989
1278
1868
3630
4702
3409
4887
2383
ELF #17104
7496
5265
8078
8788
7402
3601
2641
1252
4994
ELF #14074
7524
8889
9290
8892
5785
2163
1074
6747
ELF #17452
8006
12427
7919
4012
6850
ELF #134591
26861
ELF #113028
12695
12762
11006
15937
ELF #117218
12408
17554
11415
ELF #11118
7240
6400
3431
1032
3283
4667
6100
5076
1101
6952
3527
ELF #17633
4385
4510
4073
3052
11738
ELF #133554
ELF #13448
16054
10839
ELF #14496
2697
4731
5150
5327
4039
4004
2148
6150
4001
2882
5780
4327
ELF #14095
2064
6701
3828
2427
4775
2583
2000
1390
7391
1701
3796
ELF #110355
1262
8781
6350
ELF #111053
11527
1389
6007
12383
11033
ELF #17951
4258
9815
10061
7579
3769
11431
ELF #13597
35622
ELF #12129
2994
4260
5269
4179
1612
3509
3581
4544
3713
3202
6458
1203
1095
ELF #117196
13475
12666
ELF #13549
6432
6593
6723
1272
4023
2112
2844
5135
5103
1585
4773
5635
ELF #18731
16378
5076
2999
ELF #111136
1525
8684
9731
9753
5366
7399
ELF #18996
1483
4922
1191
2761
(It goes on and on. Each occurence of "ELF #" Is supposed to indicate a new record)
So my code looks like the following, and it just displays blank spaces when I run it. Any suggestions on why I am getting file management wrong? And how should I fix it
IDENTIFICATION DIVISION.
PROGRAM-ID. COBSHL03.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT ELF-INNPUT ASSIGN TO "C:\Users\dsdsd\Desktop\innput.DAT"
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS DOING-ITS-BEST.
DATA DIVISION.
FILE SECTION.
FD ELF-INNPUT.
01 ELF-RECS.
05 ELF-CAL PIC X(9).
05 ELF-NUM PIC X(10).
WORKING-STORAGE SECTION.
01 CACLULATIONS.
03 COUNT-OF-ELF PIC X(6).
03 ELF-CAL-TOTAL PIC 9(6).
01 DOING-ITS-BEST PIC X(900).
PROCEDURE DIVISION.
PROGRAM-BEGIN.
OPEN INPUT ELF-INNPUT.
DISPLAY ELF-RECS.
CLOSE ELF-INNPUT.
PROGRAM-DONE.
STOP RUN.

You OPEN and CLOSE the file, it looks like you've missed to READ it, likely in a loop checking the defined io-status (which is a PIC XX item).

Related

Simple Pattern match with a field and a variable does not seem to work in GAWK/AWK

I am trying to extract all lines where a field matches a pattern which is defined as a variable.
I tried the following
head input.dat |
awk -F '|' -v CODE="39905|19043" '{print $13; if($13~CODE){print "Matched"} else {print "Nomatch"} }'
I am printing the value of the field before attempting a pattern match.(This way I don't have to show the entire line that contains many fields)
This is the output I got.
PLAN_ID
Nomatch
39905
Nomatch
39905
Nomatch
39883
Nomatch
19043
Nomatch
2215
Nomatch
19043
Nomatch
9149
Nomatch
42718
Nomatch
24
Nomatch
I expected to see at least 3 instances of Matched in the output. What am I doing wrong?
edit by #Fravadona
xxd input.dat | head -n 6
00000000: fffe 4d00 4f00 4e00 5400 4800 5f00 4900 ..M.O.N.T.H._.I.
00000010: 4400 7c00 5300 5600 4300 5f00 4400 5400 D.|.S.V.C._.D.T.
00000020: 7c00 5000 4100 5400 4900 4500 4e00 5400 |.P.A.T.I.E.N.T.
00000030: 5f00 4900 4400 7c00 5000 4100 5400 5f00 .I.D.|.P.A.T..
00000040: 5a00 4900 5000 3300 7c00 4300 4c00 4100 Z.I.P.3.|.C.L.A.
00000050: 4900 4d00 5f00 4900 4400 7c00 5300 5600 I.M._.I.D.|.S.V.
Turns out that the input file uses the UTF-16 LE Encoding (as shown by the hexdump of the content). Thus, the solution seems to be to convert the input file from UTF-16LE to UTF-8 before running AWK. Thanks
I found out (thanks to all who suggested looking at the hexdump of the input file) that the file used UTF-16LE encoding. Once I converted the input file using iconv , the AWK script worked as expected

How to detect an event and ensure its the first (earliest event that occurred?

I am attempting to extract data from a large patient database using SQL. I need to detect when an event occurred. In this case, it will be a decrease in SpO2 by 10% from when treatment started. It needs to be the earliest time point when it decreased. Example 100%-95-92-97-88-92-89 only the 88 is what I will need. The tricky part begins as patients might have two treatments throughout care. I need to compare these treatments to observe which treatment is the best. An example of the data is below.
The patient will have treatment A until treatment B starts or until the final reading and vis versa. the SpO2 values with ** are the ones I need to extract
Date
Time
SpO2
Treatment
05/19/22
18:23
100
N/A
05/19/22
18:24
95
A
05/19/22
18:25
90
N/A
05/19/22
18:26
85
N/A
05/19/22
18:27
N/A
B
05/19/22
18:27
90
N/A
05/19/22
18:28
85
N/A
05/19/22
18:29
80
N/A
05/19/22
18:30
78
N/A
05/19/22
18:31
76
N/A
What I'm hoping the final table looks like is
Date
Time
SpO2
Treatment
05/19/22
18:23
100
N/A
05/19/22
18:24
95
A
05/19/22
18:26
85
N/A
05/19/22
18:27
N/A
B
05/19/22
18:27
90
N/A
05/19/22
18:29
80
N/A
If you can please help, that would be amazing and thank you very much.

Change language for return value of weekdayname

I'm printing some weekdays to a spreadsheet using the weekdayname-function. This works fine, except that the weekdays are written in the local language (Norwegian), instead of in English as I want it to. Is there any way to specify what language the function returns its results it, or am I stuck making my own UDF?
Try this
Debug.Print Application.WorksheetFunction.Text(1,"[$-414]DDDD")
Returns søndag for WeekDay 1 for Norwegian_Bokmal (414)
For a complete list of ID's see the link List of Language Packs and Their Codes for Windows 2000 Domain Controllers
In case that link ever dies, here is the complete list
Locale/language Language ID in hexadecimal
-------------------------------------------------------
Afrikaans 436
Albanian 041c
Arabic_Saudi_Arabia 401
Arabic_Iraq 801
Arabic_Egypt 0c01
Arabic_Libya 1001
Arabic_Algeria 1401
Arabic_Morocco 1801
Arabic_Tunisia 1c01
Arabic_Oman 2001
Arabic_Yemen 2401
Arabic_Syria 2801
Arabic_Jordan 2c01
Arabic_Lebanon 3 001
Arabic_Kuwait 3401
Arabic_UAE 3801
Arabic_Bahrain 3c01
Arabic_Qatar 4001
Armenian 042b
Azeri_Latin 042c
Azeri_Cyrillic 082c
Basque 042d
Belarusian 423
Bulgarian 402
Catalan 403
Chinese_Taiwan 404
Chinese_PRC 804
Chinese_Hong_Kong 0c04
Chinese_Singapore 1004
Chinese_Macau 1404
Croatian 041a
Czech 405
Danish 406
Dutch_Standard 413
Dutch_Belgian 813
English_United_States 409
English_United_Kingdom 809
English_Australian 0c09
English_Canadian 1009
English_New_Zealand 1409
English_Irish 1809
English_South_Africa 1c09
English_Jamaica 2009
English_Caribbean 2409
English_Belize 2809
English_Trinidad 2c09
English_Zimbabwe 3009
English_Philippines 3409
Estonian 425
Faeroese 438
Farsi 429
Finnish 040b
French_Standard 040c
French_Belgian 080c
French_Canadian 0c0c
French_Swiss 100c
French_Luxembourg 140c
French_Monaco 180c
Georgian 437
German_Standard 407
German_Swiss 807
German_Austrian 0c07
German_Luxembourg 1007
German_Liechtenstein 1407
Greek 408
Hebrew 040d
Hindi 439
Hungarian 040e
Icelandic 040f
Indonesian 421
Italian_Standard 410
Italian_Swiss 810
Japanese 411
Kazakh 043f
Konkani 457
Korean 412
Latvian 426
Lithuanian 427
FYRO Macedonian 042f
Malay_Malaysia 043e
Malay_Brunei_Darussalam 083e
Marathi 044e
Norwegian_Bokmal 414
Norwegian_Nynorsk 814
Polish 415
Portuguese_Brazilian 416
Portuguese_Standard 816
Romanian 418
Russian 419
Sanskrit 044f
Serbian_Latin 081a
Serbian_Cyrillic 0c1a
Slovak 041b
Slovenian 424
Spanish_Traditional_Sort 040a
Spanish_Mexican 080a
Spanish_Modern_Sort 0c0a
Spanish_Guatemala 100a
Spanish_Costa_Rica 140a
Spanish_Panama 180a
Spanish_Dominican_Republic 1c0a
Spanish_Venezuela 200a
Spanish_Colombia 240a
Spanish_Peru 280a
Spanish_Argentina 2c0a
Spanish_Ecuador 300a
Spanish_Chile 340a
Spanish_Uruguay 380a
Spanish_Paraguay 3c0a
Spanish_Bolivia 400a
Spanish_El_Salvador 440a
Spanish_Honduras 480a
Spanish_Nicaragua 4c0a
Spanish_Puerto_Rico 500a
Swahili 441
Swedish 041d
Swedish_Finland 081d
Tamil 449
Tatar 444
Thai 041e
Turkish 041f
Ukrainian 422
Urdu 420
Uzbek_Latin 443
Uzbek_Cyrillic 843
Vietnamese 042a

How to read data on a specific row from excel by asking the name of that row?

I have the following excel file:
W1000x554 1032 408 52.1 29.5 70700 12300
W1000x539 1030 407 51.1 28.4 68700 12000
W1000x483 1020 404 46 25.4 61500 10700
W1000x443 1012 402 41.9 23.6 56400 9670
W1000x412 1008 402 40 21.1 52500 9100
W1000x371 1000 400 36.1 19 47300 8140
W1000x321 990 400 31 16.5 40900 6960
W1000x296 982 400 27.1 16.5 37800 6200
W1000x584 1056 314 64 36.1 74500 12500
I want to define a function that can ask the user for one of the first column's names and then read all the relevant data of that row later.
For example if the user defines W1000x412 then read : 1008 402 40 21.1 52500 9100.
Any ideas?
I suspect what #Marc means is that a formula such as in J2 below (copied across and down as necessary) will 'pick out' the values you want. It is not clear to me from your question whether these should be kept separate (as in Row2 of example) or strung together (CONCATENATE [&] as in J7 of example, where these are space [" "] delimited):
I am also not entirely sure about your 'define a function' but have assumed you do not require a UDF.
I have used Row1 to provide the offset for VLOOKUP, to save adjusting manually the formula for each column.
ColumnI is the expected user input, that might be best by selection from a Data Validation List with Source $A$2:$A$10.

Awk - how to print the number?

I have a test file:
0000 850 1300 Pump 4112 893 2400 Installing sleeve 5910 890 2202 Installing tool
Testing crankcase and Protecting oil seal Installing crankshaft
carburetor for leaks (starter side) 5910 890 2208 Installing tool, 8
0000 855 8106 Sealing plate 4112 893 2401 Press sleeve Installing hookless
Sealing exhaust port Installing oil seal snap rings in piston
0000 855 9200 Nipple (clutch side) 5910 890 2301 Screwdriver, T20
Testing carburetor for 4118 890 6400 Setting gauge Separating handle
leaks Setting air gap moldings
0000 890 1701 Testing tool kit between ignition 5910 890 2400 Screwdriver, T27x150
0000 893 2600 Clamping strap module and flywheel For all IS screw
I want to print only:
0000 850 1300
4112 893 2400
5910 890 2202
5910 890 2208
0000 855 8106
.
.
.
Thank you for your help.
EDIT:
The numbers in the file are in different places. The numbers are randomly placed in the input file. Each number is the format:
xxxx xxx xxxx
EDIT-1:
I tried two ways, but it does not work on mawk:
pic#pic:~/Pulpit$ mawk --traditional -f script.awk infile
mawk: not an option: --traditional
pic#pic:~/Pulpit$ mawk -f script.awk infile
pic#pic:~/Pulpit$
One way with grep (if your version supports the -P flag):
grep -oP "[0-9]{4} [0-9]{3} [0-9]{4}" file.txt
Output:
0000 850 1300
4112 893 2400
5910 890 2202
5910 890 2208
0000 855 8106
4112 893 2401
0000 855 9200
5910 890 2301
4118 890 6400
0000 890 1701
5910 890 2400
0000 893 2600
HTH
This is shorter and looks for the specific pattern:
mawk '
BEGIN {
d = "[0-9]"
};
{
offset = 1;
while (RSTART + RLENGTH < length($0)) {
if (! match(substr($0, offset), d d d d " " d d d " " d d d d)) {
next
};
print substr($0, RSTART+offset - 1, RLENGTH);
offset = RSTART + RLENGTH + offset
}
}' inputfile
One way using awk:
Assuming infile has the content provided in your question:
Content of script.awk:
{
## Traverse all words of the line but last two. I assume to print three
## consecutive number fields.
i = 1
while ( i <= NF - 3 ) {
## Set current word position in line.
j = i
## Get next word while current one is a digit, and save it to print later.
while ( $j ~ /^[[:digit:]]+$/ ) {
value[j] = $j
++j
}
## If found three consecutive number fields, print them and update counter of
## words in the line.
if ( i + 3 == j ) {
for ( key in value ) {
printf "%s ", value[key]
}
printf ORS
i += 3
}
else {
## Failed the search, go to next field and try again.
++i
}
## Delete array where I save numbers.
# delete value <--- Commented for compatibility with older versions.
for ( key in value ) {
delete value[key]
}
}
}
Run it like:
awk -f script.awk infile
With following output:
0000 850 1300
4112 893 2400
5910 890 2202
5910 890 2208
0000 855 8106
4112 893 2401
0000 855 9200
5910 890 2301
4118 890 6400
0000 890 1701
5910 890 2400
0000 893 2600