I'm trying to rearrange from a specific string into the respective column. Here is the input
String 1: 47/13528
String 2: 55(s)
String 3:
String 4: 114(n)
String 5: 225(s), 26/10533-10541
String 6: 103/13519
String 7: 10(s), 162(n)
String 8: 152/12345,12346
(d=dead, n=null, s=strike)
The alphabet in each value is the flag (d=dead, n=null, s=strike). The String with value (digit) which is "String 1" will be the 47c1 etc:
String 1: 47/13528
value without any flag will be sorted into the null column along with null tag (n)
String 1 (the integer will be concatenated with 47/13528)
Sorted :
null
47c1@SP13528;114c4;103c6@SP13519;162c7
Str#2: 55(s)
flagged with (s) will be sorted into strike column
Sorted :
strike
55c2;225c5;26c5@SP10533-10541;162c7
I'm trying to parse it by modifying previous code, seems no luck
{
for (i=1; i<=NF; i++) {
num = $i+0
abbr = $i
gsub(/[^[:alpha:]]/,"",abbr)
list[abbr] = list[abbr] num " c " val ORS
}
}
END {
n = split("dead null strike",types)
for (i=1; i<=n; i++) {
name = types[i]
abbr = substr(name,1,1)
printf "name,list[abbr]\n"
}
}
Expected Output (sorted into csv) :
dead,null,strike
,47c1@SP13528;114c4; 26c5@SP10533-10541;103c6@SP13519;162c7, 152c8@SP12345;152c8@SP12346,55c2;225c5;162c7;10c7
Breakdown for crosscheck purpose:
dead
none
null
47c1@SP13528;114c4;103c6@SP13519;162c7;152c8@SP12345;152c8@SP12346;26c5@SP10533-10541;;162c7
strike
55c2;225c5;10c7
name,list[abbr]so you have to remove quotes in order to print the variables. Then you see what it prints, if it is not the desired output, you can add a fewprintstatements inside your loop, to see what is being done for a line.String 7: 10(s), 162(n)makes one item forsand one forn. This rowString 5: 225(s), 26/10533-10541should make one item forsand one fornas you have said thatnis default when no type exists. But in your example output, this row makes two items fors(based on the firsts?) which makes your description not determinative for the output you really want.sand not following your description:26c5@SP10533-10541and162c7.