-3

the data is something like

"1||2""3""2||3""5""4||3""6""43""4||4||3""4||3", 43 ,"4||3""43""3||4||4||3"

i've tried this myself

BEGIN {
    FPAT = "(\"[^\"]+\")|([ ])"
}

{
    print "NF = ", NF
    for (i = 1; i <= NF; i++) {
        printf("$%d = <%s>\n", i, $i)
    }
}

but the problem is it's giving me an output like

$ gawk -f prog4.awk data1.txt
NF =  18
$1 = <"1||2">
$2 = <"3">
$3 = <"2||3">
$4 = <"5">
$5 = <"4||3">
$6 = <"6">
$7 = <"43">
$8 = <"4||4||3">
$9 = <"4||3">
$10 = <,>
$11 = < >
$12 = <4>
$13 = <3>
$14 = < >
$15 = <,>
$16 = <"4||3">
$17 = <"43">
$18 = <"3||4||4||3">
>

as you can see $10 to $15 each and every character is taken. help appreciated.

bongboy
  • 147
  • 1
  • 15
  • 2
    it is not very clear what you mean. Could you indicate what is your final goal, together with the desired output? – fedorqui Feb 18 '15 at 11:04
  • here i separated the data column wise... the original data file doesn't have any white space. & the field separator is defined the values inside quotation marks. & some data ie. on row 3 have white space. i hope this will help. – bongboy Feb 18 '15 at 11:13
  • 3
    Update the question with this info. Comments shouldn't be used to explain the question, since not everybody reads them and also because in the question you can show how things look like... and they can look quite better in there. – fedorqui Feb 18 '15 at 11:15
  • 1
    I still have no idea what the task is or how to interpret the example. – tripleee Feb 18 '15 at 11:27
  • @tripleee clearly they want to separate the field with the field... –  Feb 18 '15 at 11:51
  • 1
    Clearly you have clairvoyant powers. Now if you can explain what the field with the field is ...? – tripleee Feb 18 '15 at 12:08
  • 2
    I think things are improving but you still haven't shown us the output you WANT to get or even descried what it it you're trying to do so we're still unable to help. We do NOT need to see a line that's 50 characters long, btw - give us 4 or 5 lines each less than, say, 10-15 characters long. – Ed Morton Feb 18 '15 at 13:39
  • the output is supposed to generate in this way $1 = <"1||2"> $2 = <"3"> $3 = <"2||3"> $4 = <"5"> $5 = <"4||3"> $6 = <"6"> $7 = <"43"> $8 = <"4||4||3"> $9 = <"4||3"> $10 = <43> $11 = <"4||3"> $12 = <"43"> $13 = <"3||4||4||3"> – bongboy Feb 18 '15 at 13:41
  • Looks like you have some unstructured data trash as input.. To achieve the expected output you can use : `sed -r 's/(, *|")([^",]*)(,|")/\2\n/g' input.file` (in the hope that your given example input is really descriptive for all input) – hek2mgl Feb 18 '15 at 13:47
  • 3
    Try and read [How do I ask a good question](http://stackoverflow.com/help/how-to-ask) --> "Pretend you're talking to a busy colleague and have to sum up your entire question in one sentence: what details can you include that will help someone identify and solve your problem? Include any error messages, key APIs, or unusual circumstances that make your question different from similar questions already on the site. " – fedorqui Feb 18 '15 at 13:47
  • 1
    @tripleee Didn't see your reply, i was joking :) –  Feb 18 '15 at 14:01
  • 1
    @user1934116 edit your question to show the desired output, don't try to put it in a comment where you can't format it. Also, add the explanation for WHY that'd be the desired output and give us a couple of lines of input at least, not just 1. – Ed Morton Feb 18 '15 at 14:38
  • i'm extremely sorry guys and please do accept my sincere apology & thank you for having patience to answer my question. – bongboy Feb 18 '15 at 18:29

1 Answers1

0

Let's try approaching this a different way - if the following is not what you are looking for, please tell us in what way(s) it differs from your desired output and why:

$ cat tst.awk
BEGIN { FPAT="\"[^\"]+\"" }
{
    for (i=1; i<=NF; i++) {
        print i, "<" $i ">"
    }
}
$ 
$ gawk -f tst.awk file
1 <"1||2">
2 <"3">
3 <"2||3">
4 <"5">
5 <"4||3">
6 <"6">
7 <"43">
8 <"4||4||3">
9 <"4||3">
10 <"4||3">
11 <"43">
12 <"3||4||4||3">
Ed Morton
  • 188,023
  • 17
  • 78
  • 185