awk -F"[{=}]" '!($1 in A) {key[++key[0]]=$1} {a[$1]=a[$1]" "$2;next} END { for(i=1;i<=key[0]/2;i++){ print key a[key]}}' | sed '/^[ ]*$/d' input_file.txt
Above worked fine for me
here is the output i got for your input file
rule
name mainrule rule2
filt pos neg
loc
x right + 660 890
y top - 3100 100
object_kind DRAW shape
object_name pen ink
sym_name_expr 123 321
anchor 0 1.5
pol 1 0
rot 0 90
angle 0 90
mirror no yes
text
x_size 0 1
y_size 0 1
width 0 1
I tried the below code in Bash shell, but i am getting error as "syntax error near unexpected token '$'do\r'' .
kindly clarify.....
Code used:
test=testfile
count=1
for i in `awk '{FS="[{}= \t]+";print $1}' $test`
do
a=`grep -w $i $test | awk '{FS="[{}= \t]+";for (i=2;i<=NF;i++)print $i}' | xargs`
if [[ $i == "rule" && $count -ne 1 ]];then
break
fi
echo $i $a
(( count = $count + 1 ))
done
Thanks in advance
vasnath
-----Post Update-----
Dear panyam,
i have used the below code, which you referred....
awk -F"[{=}]" '!($1 in A) {key[++key[0]]=$1} {a[$1]=a[$1]" "$2;next} END { for(i=1;i<=key[0]/2;i++){ print key [i]a[key[i]]}}' | sed '/^[ ]*$/d' input_file.txt
I am getting the output, same as input. It is working just like cat command.
awk -F"[{=}]" '!($1 in a) {key[++key[0]]=$1} {a[$1]=a[$1]" "$2;next} END { for(i=1;i<=key[0];i++){ print key a[key]}}' input_file_name.txt | sed '/^[ ]*$/d'
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.