oldDoctor
oldDoctor

Reputation: 59

Is awk a good tool for data extraction along with java?

I am using awk for data extraction on .csv file and am trying to display the extracted data using java. The bash script (awk) is running perfect individually but when run with java, the program crashes for data greater than 3000 values (in csv).Is there a problem with my awk expression or awk is not a good combination with java?

Bash script:

#!/bin/bash
echo "hello"
echo "gracias"
awk -F "\"*,\"*" '{print $1,$2}' data3.csv

Java Code:

import java.io.*;
public class Test {

    public static void main(String[] args) throws Exception {

        int count = 0;
            try {
                    String target = new String("/home/arohan/ab/assignment/test.sh");

                    Runtime rt = Runtime.getRuntime();
                    Process proc = rt.exec(target);
                    proc.waitFor();
                    StringBuffer output = new StringBuffer();
                    BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
                    String line = "";                       
                    while ((line = reader.readLine())!= null) {
                            output.append(line + "\n");
            count++;
                    }
                    System.out.println("### " + output);
        System.out.println(count);
            } catch (Throwable t) {
                    t.printStackTrace();
            }
    }

}

csv file:



38.55042047 39.55042047
39.55042047 40.55042047
40.55042047 41.55042047
41.55042047 42.55042047
42.55042047 43.55042047
43.55042047 44.55042047
44.55042047 45.55042047
45.55042047 46.55042047
46.55042047 47.55042047
47.55042047 48.55042047
48.55042047 49.55042047
49.55042047 50.55042047
50.55042047 51.55042047
51.55042047 52.55042047
52.55042047 53.55042047
53.55042047 54.55042047
54.55042047 55.55042047
55.55042047 56.55042047
56.55042047 57.55042047
57.55042047 58.55042047
58.55042047 59.55042047
59.55042047 60.55042047
60.55042047 61.55042047
61.55042047 62.55042047
62.55042047 63.55042047
63.55042047 64.55042047
64.55042047 65.55042047
65.55042047 66.55042047
66.55042047 67.55042047
67.55042047 68.55042047
68.55042047 69.55042047
69.55042047 70.55042047
70.55042047 71.55042047
71.55042047 72.55042047
72.55042047 73.55042047
73.55042047 74.55042047
74.55042047 75.55042047
75.55042047 76.55042047
76.55042047 77.55042047
77.55042047 78.55042047
78.55042047 79.55042047
79.55042047 80.55042047
80.55042047 81.55042047
81.55042047 82.55042047
82.55042047 83.55042047
83.55042047 84.55042047
84.55042047 85.55042047
85.55042047 86.55042047
86.55042047 87.55042047
87.55042047 88.55042047
88.55042047 89.55042047
89.55042047 90.55042047
90.55042047 91.55042047
91.55042047 92.55042047
92.55042047 93.55042047
93.55042047 94.55042047
94.55042047 95.55042047
95.55042047 96.55042047
96.55042047 97.55042047
97.55042047 98.55042047
98.55042047 99.55042047
99.55042047 100.55042047
100.55042047    101.55042047
101.55042047    102.55042047
102.55042047    103.55042047
103.55042047    104.55042047
104.55042047    105.55042047
105.55042047    106.55042047
106.55042047    107.55042047
107.55042047    108.55042047
108.55042047    109.55042047
109.55042047    110.55042047
110.55042047    111.55042047
111.55042047    112.55042047
112.55042047    113.55042047
113.55042047    114.55042047
114.55042047    115.55042047
115.55042047    116.55042047
116.55042047    117.55042047
117.55042047    118.55042047
118.55042047    119.55042047
119.55042047    120.55042047
120.55042047    121.55042047
121.55042047    122.55042047
122.55042047    123.55042047
123.55042047    124.55042047
124.55042047    125.55042047
125.55042047    126.55042047
126.55042047    127.55042047
127.55042047    128.55042047
128.55042047    129.55042047
129.55042047    130.55042047
130.55042047    131.55042047
131.55042047    132.55042047
132.55042047    133.55042047
133.55042047    134.55042047
134.55042047    135.55042047
135.55042047    136.55042047
136.55042047    137.55042047
137.55042047    138.55042047
138.55042047    139.55042047
139.55042047    140.55042047
140.55042047    141.55042047
141.55042047    142.55042047
142.55042047    143.55042047
143.55042047    144.55042047
144.55042047    145.55042047
145.55042047    146.55042047
146.55042047    147.55042047
147.55042047    148.55042047
148.55042047    149.55042047
149.55042047    150.55042047
150.55042047    151.55042047
151.55042047    152.55042047
152.55042047    153.55042047
153.55042047    154.55042047
154.55042047    155.55042047
155.55042047    156.55042047
156.55042047    157.55042047
157.55042047    158.55042047
158.55042047    159.55042047
159.55042047    160.55042047
160.55042047    161.55042047
161.55042047    162.55042047
162.55042047    163.55042047
163.55042047    164.55042047
164.55042047    165.55042047
165.55042047    166.55042047
166.55042047    167.55042047
167.55042047    168.55042047
168.55042047    169.55042047
169.55042047    170.55042047
170.55042047    171.55042047
171.55042047    172.55042047
172.55042047    173.55042047
173.55042047    174.55042047
174.55042047    175.55042047
175.55042047    176.55042047
176.55042047    177.55042047
177.55042047    178.55042047
178.55042047    179.55042047
179.55042047    180.55042047
180.55042047    181.55042047
181.55042047    182.55042047
182.55042047    183.55042047
183.55042047    184.55042047
184.55042047    185.55042047
185.55042047    186.55042047
186.55042047    187.55042047
187.55042047    188.55042047
188.55042047    189.55042047
189.55042047    190.55042047
190.55042047    191.55042047
191.55042047    192.55042047
192.55042047    193.55042047
193.55042047    194.55042047
194.55042047    195.55042047
195.55042047    196.55042047
196.55042047    197.55042047
197.55042047    198.55042047
198.55042047    199.55042047
199.55042047    200.55042047
200.55042047    201.55042047
201.55042047    202.55042047
202.55042047    203.55042047
203.55042047    204.55042047
204.55042047    205.55042047
205.55042047    206.55042047
206.55042047    207.55042047
207.55042047    208.55042047
208.55042047    209.55042047
209.55042047    210.55042047
210.55042047    211.55042047
211.55042047    212.55042047
212.55042047    213.55042047
213.55042047    214.55042047
214.55042047    215.55042047
215.55042047    216.55042047
216.55042047    217.55042047
217.55042047    218.55042047
218.55042047    219.55042047
219.55042047    220.55042047
220.55042047    221.55042047
221.55042047    222.55042047
222.55042047    223.55042047
223.55042047    224.55042047
224.55042047    225.55042047
225.55042047    226.55042047
226.55042047    227.55042047
227.55042047    228.55042047
228.55042047    229.55042047
229.55042047    230.55042047
230.55042047    231.55042047
231.55042047    232.55042047
232.55042047    233.55042047
233.55042047    234.55042047
234.55042047    235.55042047
235.55042047    236.55042047
236.55042047    237.55042047
237.55042047    238.55042047
238.55042047    239.55042047
239.55042047    240.55042047
240.55042047    241.55042047
241.55042047    242.55042047
242.55042047    243.55042047
243.55042047    244.55042047
244.55042047    245.55042047
245.55042047    246.55042047
246.55042047    247.55042047
247.55042047    248.55042047
248.55042047    249.55042047
249.55042047    250.55042047
250.55042047    251.55042047
251.55042047    252.55042047
252.55042047    253.55042047
253.55042047    254.55042047
254.55042047    255.55042047
255.55042047    256.55042047
256.55042047    257.55042047
257.55042047    258.55042047
258.55042047    259.55042047
259.55042047    260.55042047
260.55042047    261.55042047
261.55042047    262.55042047
262.55042047    263.55042047
263.55042047    264.55042047
264.55042047    265.55042047
265.55042047    266.55042047
266.55042047    267.55042047
267.55042047    268.55042047
268.55042047    269.55042047
269.55042047    270.55042047
270.55042047    271.55042047
271.55042047    272.55042047
272.55042047    273.55042047
273.55042047    274.55042047
274.55042047    275.55042047
275.55042047    276.55042047
276.55042047    277.55042047
277.55042047    278.55042047
278.55042047    279.55042047
279.55042047    280.55042047
280.55042047    281.55042047
281.55042047    282.55042047
282.55042047    283.55042047
283.55042047    284.55042047
284.55042047    285.55042047
285.55042047    286.55042047
286.55042047    287.55042047
287.55042047    288.55042047
288.55042047    289.55042047
289.55042047    290.55042047
290.55042047    291.55042047
291.55042047    292.55042047
292.55042047    293.55042047
293.55042047    294.55042047
294.55042047    295.55042047
295.55042047    296.55042047
296.55042047    297.55042047
297.55042047    298.55042047
298.55042047    299.55042047
299.55042047    300.55042047
300.55042047    301.55042047
301.55042047    302.55042047
302.55042047    303.55042047
303.55042047    304.55042047
304.55042047    305.55042047
305.55042047    306.55042047
306.55042047    307.55042047
307.55042047    308.55042047
308.55042047    309.55042047
309.55042047    310.55042047
310.55042047    311.55042047
311.55042047    312.55042047
312.55042047    313.55042047
313.55042047    314.55042047
314.55042047    315.55042047
315.55042047    316.55042047
316.55042047    317.55042047
317.55042047    318.55042047
318.55042047    319.55042047
319.55042047    320.55042047
320.55042047    321.55042047
321.55042047    322.55042047
322.55042047    323.55042047
323.55042047    324.55042047
324.55042047    325.55042047
325.55042047    326.55042047
326.55042047    327.55042047
327.55042047    328.55042047
328.55042047    329.55042047
329.55042047    330.55042047
330.55042047    331.55042047
331.55042047    332.55042047
332.55042047    333.55042047
333.55042047    334.55042047
334.55042047    335.55042047
335.55042047    336.55042047
336.55042047    337.55042047
337.55042047    338.55042047
338.55042047    339.55042047
339.55042047    340.55042047
340.55042047    341.55042047
341.55042047    342.55042047
342.55042047    343.55042047
343.55042047    344.55042047
344.55042047    345.55042047
345.55042047    346.55042047
346.55042047    347.55042047
347.55042047    348.55042047
348.55042047    349.55042047
349.55042047    350.55042047
350.55042047    351.55042047
351.55042047    352.55042047
352.55042047    353.55042047
353.55042047    354.55042047
354.55042047    355.55042047
355.55042047    356.55042047
356.55042047    357.55042047
357.55042047    358.55042047
358.55042047    359.55042047
359.55042047    360.55042047
360.55042047    361.55042047
361.55042047    362.55042047
362.55042047    363.55042047
363.55042047    364.55042047
364.55042047    365.55042047
365.55042047    366.55042047
366.55042047    367.55042047
367.55042047    368.55042047
368.55042047    369.55042047
369.55042047    370.55042047
370.55042047    371.55042047
371.55042047    372.55042047
372.55042047    373.55042047
373.55042047    374.55042047
374.55042047    375.55042047
375.55042047    376.55042047
376.55042047    377.55042047
377.55042047    378.55042047
378.55042047    379.55042047
379.55042047    380.55042047
380.55042047    381.55042047
381.55042047    382.55042047
382.55042047    383.55042047
383.55042047    384.55042047
384.55042047    385.55042047
385.55042047    386.55042047
386.55042047    387.55042047
387.55042047    388.55042047
388.55042047    389.55042047
389.55042047    390.55042047
390.55042047    391.55042047
391.55042047    392.55042047
392.55042047    393.55042047
393.55042047    394.55042047
394.55042047    395.55042047
395.55042047    396.55042047
396.55042047    397.55042047
397.55042047    398.55042047
398.55042047    399.55042047
399.55042047    400.55042047
400.55042047    401.55042047
401.55042047    402.55042047
402.55042047    403.55042047
403.55042047    404.55042047
404.55042047    405.55042047
405.55042047    406.55042047
406.55042047    407.55042047
407.55042047    408.55042047
408.55042047    409.55042047
409.55042047    410.55042047
410.55042047    411.55042047
411.55042047    412.55042047
412.55042047    413.55042047
413.55042047    414.55042047
414.55042047    415.55042047
415.55042047    416.55042047
416.55042047    417.55042047
417.55042047    418.55042047
418.55042047    419.55042047
419.55042047    420.55042047
420.55042047    421.55042047
421.55042047    422.55042047
422.55042047    423.55042047
423.55042047    424.55042047
424.55042047    425.55042047
425.55042047    426.55042047
426.55042047    427.55042047
427.55042047    428.55042047
428.55042047    429.55042047
429.55042047    430.55042047
430.55042047    431.55042047
431.55042047    432.55042047
432.55042047    433.55042047
433.55042047    434.55042047
434.55042047    435.55042047
435.55042047    436.55042047
436.55042047    437.55042047
437.55042047    438.55042047
438.55042047    439.55042047
439.55042047    440.55042047
440.55042047    441.55042047
441.55042047    442.55042047
442.55042047    443.55042047
443.55042047    444.55042047
444.55042047    445.55042047
445.55042047    446.55042047
446.55042047    447.55042047
447.55042047    448.55042047
448.55042047    449.55042047
449.55042047    450.55042047
450.55042047    451.55042047
451.55042047    452.55042047
452.55042047    453.55042047
453.55042047    454.55042047
454.55042047    455.55042047
455.55042047    456.55042047
456.55042047    457.55042047
457.55042047    458.55042047
458.55042047    459.55042047
459.55042047    460.55042047
460.55042047    461.55042047
461.55042047    462.55042047
462.55042047    463.55042047
463.55042047    464.55042047
464.55042047    465.55042047
465.55042047    466.55042047
466.55042047    467.55042047
467.55042047    468.55042047
468.55042047    469.55042047
469.55042047    470.55042047
470.55042047    471.55042047
471.55042047    472.55042047
472.55042047    473.55042047
473.55042047    474.55042047
474.55042047    475.55042047
475.55042047    476.55042047
476.55042047    477.55042047
477.55042047    478.55042047
478.55042047    479.55042047
479.55042047    480.55042047
480.55042047    481.55042047
481.55042047    482.55042047
482.55042047    483.55042047
483.55042047    484.55042047
484.55042047    485.55042047
485.55042047    486.55042047
486.55042047    487.55042047
487.55042047    488.55042047
488.55042047    489.55042047
489.55042047    490.55042047
490.55042047    491.55042047
491.55042047    492.55042047
492.55042047    493.55042047
493.55042047    494.55042047
494.55042047    495.55042047
495.55042047    496.55042047
496.55042047    497.55042047
497.55042047    498.55042047
498.55042047    499.55042047
499.55042047    500.55042047
500.55042047    501.55042047
501.55042047    502.55042047
502.55042047    503.55042047
503.55042047    504.55042047
504.55042047    505.55042047
505.55042047    506.55042047
506.55042047    507.55042047
507.55042047    508.55042047
508.55042047    509.55042047
509.55042047    510.55042047
510.55042047    511.55042047
511.55042047    512.55042047
512.55042047    513.55042047
513.55042047    514.55042047
514.55042047    515.55042047
515.55042047    516.55042047
516.55042047    517.55042047
517.55042047    518.55042047
518.55042047    519.55042047
519.55042047    520.55042047
520.55042047    521.55042047
521.55042047    522.55042047
522.55042047    523.55042047
523.55042047    524.55042047
524.55042047    525.55042047
525.55042047    526.55042047
526.55042047    527.55042047
527.55042047    528.55042047
528.55042047    529.55042047
529.55042047    530.55042047
530.55042047    531.55042047
531.55042047    532.55042047
532.55042047    533.55042047
533.55042047    534.55042047
534.55042047    535.55042047
535.55042047    536.55042047
536.55042047    537.55042047
537.55042047    538.55042047
538.55042047    539.55042047
539.55042047    540.55042047
540.55042047    541.55042047
541.55042047    542.55042047
542.55042047    543.55042047
543.55042047    544.55042047
544.55042047    545.55042047
545.55042047    546.55042047
546.55042047    547.55042047
547.55042047    548.55042047
548.55042047    549.55042047
549.55042047    550.55042047
550.55042047    551.55042047
551.55042047    552.55042047
552.55042047    553.55042047
553.55042047    554.55042047
554.55042047    555.55042047
555.55042047    556.55042047
556.55042047    557.55042047
557.55042047    558.55042047
558.55042047    559.55042047
559.55042047    560.55042047
560.55042047    561.55042047
561.55042047    562.55042047
562.55042047    563.55042047
563.55042047    564.55042047
564.55042047    565.55042047
565.55042047    566.55042047
566.55042047    567.55042047
567.55042047    568.55042047
568.55042047    569.55042047
569.55042047    570.55042047
570.55042047    571.55042047
571.55042047    572.55042047
572.55042047    573.55042047
573.55042047    574.55042047
574.55042047    575.55042047
575.55042047    576.55042047
576.55042047    577.55042047
577.55042047    578.55042047
578.55042047    579.55042047
579.55042047    580.55042047
580.55042047    581.55042047
581.55042047    582.55042047
582.55042047    583.55042047
583.55042047    584.55042047
584.55042047    585.55042047
585.55042047    586.55042047
586.55042047    587.55042047
587.55042047    588.55042047
588.55042047    589.55042047
589.55042047    590.55042047
590.55042047    591.55042047
591.55042047    592.55042047
592.55042047    593.55042047
593.55042047    594.55042047
594.55042047    595.55042047
595.55042047    596.55042047
596.55042047    597.55042047
597.55042047    598.55042047
598.55042047    599.55042047
599.55042047    600.55042047
600.55042047    601.55042047
601.55042047    602.55042047
602.55042047    603.55042047
603.55042047    604.55042047
604.55042047    605.55042047
605.55042047    606.55042047
606.55042047    607.55042047
607.55042047    608.55042047
608.55042047    609.55042047
609.55042047    610.55042047
610.55042047    611.55042047
611.55042047    612.55042047
612.55042047    613.55042047
613.55042047    614.55042047
614.55042047    615.55042047
615.55042047    616.55042047
616.55042047    617.55042047
617.55042047    618.55042047
618.55042047    619.55042047
619.55042047    620.55042047
620.55042047    621.55042047
621.55042047    622.55042047
622.55042047    623.55042047
623.55042047    624.55042047
624.55042047    625.55042047
625.55042047    626.55042047
626.55042047    627.55042047
627.55042047    628.55042047
628.55042047    629.55042047
629.55042047    630.55042047
630.55042047    631.55042047
631.55042047    632.55042047
632.55042047    633.55042047
633.55042047    634.55042047
634.55042047    635.55042047
635.55042047    636.55042047
636.55042047    637.55042047
637.55042047    638.55042047
638.55042047    639.55042047
639.55042047    640.55042047
640.55042047    641.55042047
641.55042047    642.55042047
642.55042047    643.55042047
643.55042047    644.55042047
644.55042047    645.55042047
645.55042047    646.55042047
646.55042047    647.55042047
647.55042047    648.55042047
648.55042047    649.55042047
649.55042047    650.55042047
650.55042047    651.55042047
651.55042047    652.55042047
652.55042047    653.55042047
653.55042047    654.55042047
654.55042047    655.55042047
655.55042047    656.55042047
656.55042047    657.55042047
657.55042047    658.55042047
658.55042047    659.55042047
659.55042047    660.55042047
660.55042047    661.55042047
661.55042047    662.55042047
662.55042047    663.55042047
663.55042047    664.55042047
664.55042047    665.55042047
665.55042047    666.55042047
666.55042047    667.55042047
667.55042047    668.55042047
668.55042047    669.55042047
669.55042047    670.55042047
670.55042047    671.55042047
671.55042047    672.55042047
672.55042047    673.55042047
673.55042047    674.55042047
674.55042047    675.55042047
675.55042047    676.55042047
676.55042047    677.55042047
677.55042047    678.55042047
678.55042047    679.55042047
679.55042047    680.55042047
680.55042047    681.55042047
681.55042047    682.55042047
682.55042047    683.55042047
683.55042047    684.55042047
684.55042047    685.55042047
685.55042047    686.55042047
686.55042047    687.55042047
687.55042047    688.55042047
688.55042047    689.55042047
689.55042047    690.55042047
690.55042047    691.55042047
691.55042047    692.55042047
692.55042047    693.55042047
693.55042047    694.55042047
694.55042047    695.55042047
695.55042047    696.55042047
696.55042047    697.55042047
697.55042047    698.55042047
698.55042047    699.55042047
699.55042047    700.55042047
700.55042047    701.55042047
701.55042047    702.55042047
702.55042047    703.55042047
703.55042047    704.55042047
704.55042047    705.55042047
705.55042047    706.55042047
706.55042047    707.55042047
707.55042047    708.55042047
708.55042047    709.55042047
709.55042047    710.55042047
710.55042047    711.55042047
711.55042047    712.55042047
712.55042047    713.55042047
713.55042047    714.55042047
714.55042047    715.55042047
715.55042047    716.55042047
716.55042047    717.55042047
717.55042047    718.55042047
718.55042047    719.55042047
719.55042047    720.55042047
720.55042047    721.55042047
721.55042047    722.55042047
722.55042047    723.55042047
723.55042047    724.55042047
724.55042047    725.55042047
725.55042047    726.55042047
726.55042047    727.55042047
727.55042047    728.55042047
728.55042047    729.55042047
729.55042047    730.55042047
730.55042047    731.55042047
731.55042047    732.55042047
732.55042047    733.55042047
733.55042047    734.55042047
734.55042047    735.55042047
735.55042047    736.55042047
736.55042047    737.55042047
737.55042047    738.55042047
738.55042047    739.55042047
739.55042047    740.55042047
740.55042047    741.55042047
741.55042047    742.55042047
742.55042047    743.55042047
743.55042047    744.55042047
744.55042047    745.55042047
745.55042047    746.55042047
746.55042047    747.55042047
747.55042047    748.55042047
748.55042047    749.55042047
749.55042047    750.55042047
750.55042047    751.55042047
751.55042047    752.55042047
752.55042047    753.55042047
753.55042047    754.55042047
754.55042047    755.55042047
755.55042047    756.55042047
756.55042047    757.55042047
757.55042047    758.55042047
758.55042047    759.55042047
759.55042047    760.55042047
760.55042047    761.55042047
761.55042047    762.55042047
762.55042047    763.55042047
763.55042047    764.55042047
764.55042047    765.55042047
765.55042047    766.55042047
766.55042047    767.55042047
767.55042047    768.55042047
768.55042047    769.55042047
769.55042047    770.55042047
770.55042047    771.55042047
771.55042047    772.55042047
772.55042047    773.55042047
773.55042047    774.55042047
774.55042047    775.55042047
775.55042047    776.55042047
776.55042047    777.55042047
777.55042047    778.55042047
778.55042047    779.55042047
779.55042047    780.55042047
780.55042047    781.55042047
781.55042047    782.55042047
782.55042047    783.55042047
783.55042047    784.55042047
784.55042047    785.55042047
785.55042047    786.55042047
786.55042047    787.55042047
787.55042047    788.55042047
788.55042047    789.55042047
789.55042047    790.55042047
790.55042047    791.55042047
791.55042047    792.55042047
792.55042047    793.55042047
793.55042047    794.55042047
794.55042047    795.55042047
795.55042047    796.55042047
796.55042047    797.55042047
797.55042047    798.55042047
798.55042047    799.55042047
799.55042047    800.55042047
800.55042047    801.55042047
801.55042047    802.55042047
802.55042047    803.55042047
803.55042047    804.55042047
804.55042047    805.55042047
805.55042047    806.55042047
806.55042047    807.55042047
807.55042047    808.55042047
808.55042047    809.55042047
809.55042047    810.55042047
810.55042047    811.55042047
811.55042047    812.55042047
812.55042047    813.55042047
813.55042047    814.55042047
814.55042047    815.55042047
815.55042047    816.55042047
816.55042047    817.55042047
817.55042047    818.55042047
818.55042047    819.55042047
819.55042047    820.55042047
820.55042047    821.55042047
821.55042047    822.55042047
822.55042047    823.55042047
823.55042047    824.55042047
824.55042047    825.55042047
825.55042047    826.55042047
826.55042047    827.55042047
827.55042047    828.55042047
828.55042047    829.55042047
829.55042047    830.55042047
830.55042047    831.55042047
831.55042047    832.55042047
832.55042047    833.55042047
833.55042047    834.55042047
834.55042047    835.55042047
835.55042047    836.55042047
836.55042047    837.55042047
837.55042047    838.55042047
838.55042047    839.55042047
839.55042047    840.55042047
840.55042047    841.55042047
841.55042047    842.55042047
842.55042047    843.55042047
843.55042047    844.55042047
844.55042047    845.55042047
845.55042047    846.55042047
846.55042047    847.55042047
847.55042047    848.55042047
848.55042047    849.55042047
849.55042047    850.55042047
850.55042047    851.55042047
851.55042047    852.55042047
852.55042047    853.55042047
853.55042047    854.55042047
854.55042047    855.55042047
855.55042047    856.55042047
856.55042047    857.55042047
857.55042047    858.55042047
858.55042047    859.55042047
859.55042047    860.55042047
860.55042047    861.55042047
861.55042047    862.55042047
862.55042047    863.55042047
863.55042047    864.55042047
864.55042047    865.55042047
865.55042047    866.55042047
866.55042047    867.55042047
867.55042047    868.55042047
868.55042047    869.55042047
869.55042047    870.55042047
870.55042047    871.55042047
871.55042047    872.55042047
872.55042047    873.55042047
873.55042047    874.55042047
874.55042047    875.55042047
875.55042047    876.55042047
876.55042047    877.55042047
877.55042047    878.55042047
878.55042047    879.55042047
879.55042047    880.55042047
880.55042047    881.55042047
881.55042047    882.55042047
882.55042047    883.55042047
883.55042047    884.55042047
884.55042047    885.55042047
885.55042047    886.55042047
886.55042047    887.55042047
887.55042047    888.55042047
888.55042047    889.55042047
889.55042047    890.55042047
890.55042047    891.55042047
891.55042047    892.55042047
892.55042047    893.55042047
893.55042047    894.55042047
894.55042047    895.55042047
895.55042047    896.55042047
896.55042047    897.55042047
897.55042047    898.55042047
898.55042047    899.55042047
899.55042047    900.55042047
900.55042047    901.55042047
901.55042047    902.55042047
902.55042047    903.55042047
903.55042047    904.55042047
904.55042047    905.55042047
905.55042047    906.55042047
906.55042047    907.55042047
907.55042047    908.55042047
908.55042047    909.55042047
909.55042047    910.55042047
910.55042047    911.55042047
911.55042047    912.55042047
912.55042047    913.55042047
913.55042047    914.55042047
914.55042047    915.55042047
915.55042047    916.55042047
916.55042047    917.55042047
917.55042047    918.55042047
918.55042047    919.55042047
919.55042047    920.55042047
920.55042047    921.55042047
921.55042047    922.55042047
922.55042047    923.55042047
923.55042047    924.55042047
924.55042047    925.55042047
925.55042047    926.55042047
926.55042047    927.55042047
927.55042047    928.55042047
928.55042047    929.55042047
929.55042047    930.55042047
930.55042047    931.55042047
931.55042047    932.55042047
932.55042047    933.55042047
933.55042047    934.55042047
934.55042047    935.55042047
935.55042047    936.55042047
936.55042047    937.55042047
937.55042047    938.55042047
938.55042047    939.55042047
939.55042047    940.55042047
940.55042047    941.55042047
941.55042047    942.55042047
942.55042047    943.55042047
943.55042047    944.55042047
944.55042047    945.55042047
945.55042047    946.55042047
946.55042047    947.55042047
947.55042047    948.55042047
948.55042047    949.55042047
949.55042047    950.55042047
950.55042047    951.55042047
951.55042047    952.55042047
952.55042047    953.55042047
953.55042047    954.55042047
954.55042047    955.55042047
955.55042047    956.55042047
956.55042047    957.55042047
957.55042047    958.55042047
958.55042047    959.55042047
959.55042047    960.55042047
960.55042047    961.55042047
961.55042047    962.55042047
962.55042047    963.55042047
963.55042047    964.55042047
964.55042047    965.55042047
965.55042047    966.55042047
966.55042047    967.55042047
967.55042047    968.55042047
968.55042047    969.55042047
969.55042047    970.55042047
970.55042047    971.55042047
971.55042047    972.55042047
972.55042047    973.55042047
973.55042047    974.55042047
974.55042047    975.55042047
975.55042047    976.55042047
976.55042047    977.55042047
977.55042047    978.55042047
978.55042047    979.55042047
979.55042047    980.55042047
980.55042047    981.55042047
981.55042047    982.55042047
982.55042047    983.55042047
983.55042047    984.55042047
984.55042047    985.55042047
985.55042047    986.55042047
986.55042047    987.55042047
987.55042047    988.55042047
988.55042047    989.55042047
989.55042047    990.55042047
990.55042047    991.55042047
991.55042047    992.55042047
992.55042047    993.55042047
993.55042047    994.55042047
994.55042047    995.55042047
995.55042047    996.55042047
996.55042047    997.55042047
997.55042047    998.55042047
998.55042047    999.55042047
999.55042047    1000.55042047
1000.55042047   1001.55042047
1001.55042047   1002.55042047
1002.55042047   1003.55042047


Ps: I am attaching a sample of the csv file.

Expected Output: Display the values extracted from the csv file. (which gets displayed for values upto 2000).

Upvotes: 1

Views: 221

Answers (2)

RealSkeptic
RealSkeptic

Reputation: 34638

The quick solution

Move your proc.waitFor(); after the read loop.

Explanation: you haven't specified which error you are getting, but when you call waitFor right after you open the process, it means that the process has limited space for its output before it floods the buffer (see the answer by Bibz). Once that buffer is full, you get deadlocked.

So it will work for small data, but not for large. What you should do is let the process run and keep reading its output. Since you don't have to provide it with input at the same time, this is relatively easy - you just read until you get null. The null indicates that awk closed its output, as it finished working and terminated.

At that point, you waitFor() the process (this should return immediately, unless your script somehow does additional operations after output has been closed). This allows you to process any size of data from your subprocess.

The correct solution

As the many comments tell you, you shouldn't really be using awk or a subprocess here.

  • Awk is not designed to process standard CSV files, which may have escaped quotes and commas in them. You need a CSV parser for this.
  • Simple text processing can be done by any language. The use for awk is for times when you don't actually want to write a program in a general-purpose language at all. If you are going to write a program in any language - Java, Python, PHP, C++ - then you should be using that same language for your text processing as well.
  • Subprocesses require extra work. What if there is an error in the process? The file is not found or doesn't have permissions? In that case, the subprocess will issue an error, but you have no error checking in your code, and it's going to become very complicated once you put in the appropriate error checks and set up a thread to read the standard error as well as the standard output.

So the correct solution would be to use a CSV Parser. For example, there's Apache Commons CSV.

Where you would use something like:

 Path path = Paths.get("/path/to/data3.csv");
 try (CSVParser parser = CSVFormat.DEFAULT.parse(Files.newBufferedReader(path));) {
     for (CSVRecord csvRecord : parser) {
         System.output.println( "### " + csvRecord.get(0) + " " + csvRecord.get(1) + "\n";
     }
 }

Upvotes: 3

Bibz
Bibz

Reputation: 321

Your script's output might be too large for the buffer, from the Process API reference (emphasis mine):

By default, the created subprocess does not have its own terminal or console. All its standard I/O (i.e. stdin, stdout, stderr) operations will be redirected to the parent process, where they can be accessed via the streams obtained using the methods getOutputStream(), getInputStream(), and getErrorStream(). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, or even deadlock.

You could try to start reading your script's output before it completes, but it would not be a robust way of doing it; since both are in parallel, the script could still run all the way and overflow the buffer.

As stated in your question's comment, you should do your sting extraction directly in Java, not in an external script (read the file line by line, do extract, save output, repeat)

Upvotes: 1

Related Questions