This doesn't match what you posted in post#16.
As I said in post#17, when I do exactly what you describe in post#20, I don't have a problem, a file "output" is created with the expected contents.
What's your OS, shell, and awk versions? Any error messages when you run your approach?
I used nawk instead of awk as advised in your post #11, stil got the error below. In post #11 what do u mean by output is to stdout,PLEASE
>sh gil
nawk: you can only delete array[element] at source line 14
context is
delete RES >>>
<<< }
nawk: syntax error at source line 15
nawk: illegal statement at source line 15
@ vgersh99 and RudiC you are the best. It's working fine. It'll take at least 6 hours cause i have about 4 milions lines, but still we made it. Thank very much.
I'd be very surprised if it really took 6h, except on a very busy host. For a 15MB file with 1101925 lines:
time sh ou.awk
real 0m4.469s
user 0m4.400s
sys 0m0.040s
EDIT:
For a comparison with vgersh99's proposal in post#5:
time awk -f gil.awk DS2_export100217.ldif
real 0m1.713s
user 0m1.076s
sys 0m0.072s
And, last but not least, Corona688's proposal in post#9
time awk -f mline.awk DS2_export100217.ldif
real 0m0.833s
user 0m0.752s
sys 0m0.072s
Both use ($1 in ARRAY) which is WAY faster than my HDCM ~ "," $1 "," ; a good learning, isn't it?
EDIT2:
Applying our learning:
time ./ou.awk >output
real 0m0.678s
user 0m0.660s
sys 0m0.016s
BTW - these timings are far from being scientifically correct, reliable nor objective - other influences like file buffering etc. might heavily modify the results. They're for getting a feeling only...
@ RudiC it's really taking such time 4hrs at least. I really have to improve the time. Maybe it's my machine that's also running other stuff. But all the same the script is working perfectly.
@vgersh99 i tried the proposal on post 5, it gave me an error. I'm trying again with a file of the same size, and let you know of the timing and error if there is.
---------- Post updated at 04:23 AM ---------- Previous update was at 04:11 AM ----------
Please guys could you explain to me briefly each line of your code?
awk -F: '
BEGIN {HD="MSISDN,IMSI,NAM,TS11,TS21,TS22,TS62,BAIC,BAOC,APNID1,APNID2" # define the fields to extract, and prepare a header for eventual print
for (i=HDCnt=split(HD, HDArr, ","); i>0; i--) X[HDArr] # create am "associative" array for later $1 matching
NXTREC = "dn" # this is where the next record starts
}
$1 == NXTREC {if (PR) for (i=1; i<=HDCnt; i++) printf "%s%s", RES[HDArr], i==HDCnt?ORS:OFS
# print old record collected up to now; don't on the first record (Pr still undefined)
split ("", RES) # remoce RES array
PR = 1 # define the PR logical var so all next records are printed
}
$1 in X {RES [$1] = $0 # collect data line if $1 is among the requested fields
}
END {for (i=1; i<=HDCnt; i++) printf "%s%s", RES[HDArr], i==HDCnt?ORS:OFS
} # see above for the last record
' FS=":" OFS="," DS2_export100217.ldif
It's running but the output file is not receiving the output expected. It's taking more time to load the output file.
---------- Post updated 02-19-17 at 07:07 AM ---------- Previous update was 02-18-17 at 11:52 AM ----------
Please another script to extrat the information highlighted in yellow. Can you guys help? i tried with the other script, it's not giving the results. the results should be on the same line. Please!!
What did you try, esp. in the light of the proposals made for your first problem? Show your attempts including error messages.
Don't miss to post the expected output. Does it go to the same result file as the other fields?
@RudiC, i tried with the script, it didn't give any results at all. I lunched it, but the output file was empty. So i'm wondering whether the output was still in the buffer or something else..I'm creating a new thread for the new problem right away.