1

I've sorted it by using Google Sheet, but its gonna takes a long time, so I figured it out, to settle it down by awk.

input.txt

Column 1
2
2
2
4
4

Column 2
562
564
119
215
12

Range
13455,13457
13161
11409
13285,13277-13269
11409

I've tried this script, so it's gonna rearrange the value.

awk '/Column 1/' RS= input.txt (as referred in How can I set the grep after context to be "until the next blank line"?)

But it seems, it's only gonna take one matched line

It should be sorted by respective lines.

Result:
562Value2@13455
562Value2@13457
564Value2@13161
119Value2@11409
215Value4@13285
215Value4@13277-13269
12Value4@11409

it should be something like that, the "comma" will be repeating the value from Column 1 and Column 2 etc:

Range :
13455,13457

Result :
562Value2@13455
562Value2@13457
user10254032
  • 193
  • 7

1 Answers1

1

idk what sorting has to do with it but it seems like this is what you're looking for:

$ cat tst.awk
BEGIN { FS=","; recNr=1; print "Result:" }
!NF { ++recNr; lineNr=0; next }
{ ++lineNr }
lineNr == 1 { next }
recNr == 1  { a[lineNr] = $0 }
recNr == 2  { b[lineNr] = $0 }
recNr == 3  {
    for (i=1; i<=NF; i++) {
        print b[lineNr] "Value" a[lineNr] "@" $i
    }
}

$ awk -f tst.awk input.txt
Result:
562Value2@13455
562Value2@13457
564Value2@13161
119Value2@11409
215Value4@13285
215Value4@13277-13269
12Value4@11409
Ed Morton
  • 188,023
  • 17
  • 78
  • 185
  • btw, what is the name of this method? I need more understanding of it. Sorry for the geeky question – user10254032 Jul 23 '19 at 06:00
  • Theres no particular name for it, I just stored each of the first 2 blocks of lines (records) in arrays and then concatenated and printed them when reading the 3rd record. – Ed Morton Jul 23 '19 at 06:01
  • What if, the input doesn't have blank space, do I have to put delimiters? So I could differentiate the column. etc. by using RS – user10254032 Jul 23 '19 at 07:36
  • I wrote a script to parse the input you posted. If the input doesn't look like what you posted then, of course, you'd need to change the script to parse whatever the input actually looks like. Without seeing that input I don't know what a script to parse that input would look like. – Ed Morton Jul 23 '19 at 13:39