format data

i have this data:

GREEN LIST :
12321     34534
GREEN LIST :
45645 --- 23423
WHITE LIST :
23479     34534     75483     76924
12345 --- 12351     56778 --- 23330
GREEN LIST :
23567

the output must be:

GREEN LIST : 12321
GREEN LIST : 34534
GREEN LIST : 45645 --- 23423
WHITE LIST : 23479
WHITE LIST : 34534
WHITE LIST : 75483
WHITE LIST : 76924
WHITE LIST : 12345 --- 12351 
WHITE LIST : 56778 --- 23330
GREEN LIST : 23567

can you see what i mean? partially, i tried doing:

awk '
BEGIN { FS = "     " }
/LIST/ { tag = $1 ; next }
/[0-9]/ { print tag, $1 }' < filename

and it prints only the $1 but when i tried:

/[0-9]/ { print tag ; print $1 }' < filename

it works but the output is not what i wanted. :stuck_out_tongue:

how can we do this :slight_smile:

pls help :smiley:

Your solution might be to first remove the new line after "LIST :". I think you know better how to do it than me. At least a newline is \n you should subsitute it with nothing.
Good luck.

Regs David

i just used the following:


grep -E "LIST|^  [0-9]" ${1}  | sed 's/ --- /---/g' | sed 's/     / /g' |
awk '
/LIST/ { tag = $1 ; next }
/[0-9]/ { print tag , $0 }' > filter_out.log

cut -f1 -d" " filter_out.log > type_list.log

cut -f2 -d" " filter_out.log > field_one.log
cut -f3 -d" " filter_out.log > field_two.log
cut -f4 -d" " filter_out.log > field_three.log
cut -f5 -d" " filter_out.log > field_four.log

paste -d" " type_list.log field_one.log | grep "[0-9]" > out.txt
paste -d" " type_list.log field_two.log | grep "[0-9]"  >> out.txt 
paste -d" " type_list.log field_three.log | grep "[0-9]"  >> out.txt
paste -d" " type_list.log field_four.log | grep "[0-9]"  >> out.txt

although the output is something like:


GREEN 12321

instead of 

GREEN LIST : 12321

it works fine with me.

thanks anyway for the reply :stuck_out_tongue: