0

I have a file say f1 in the following format:

digraph G {
  rankdir=TB;
  node [style="filled", ];
  2 [label="Decl n1", fillcolor="#FFEFD5", shape=box, ];
  3 [label="In1", fillcolor="#6495ED", shape=box, ];
  4 [label="Decl n2", fillcolor="#FFEFD5", shape=box, ];
  5 [label="In2", fillcolor="#6495ED", shape=box, ];
  ...........

  edge [dir=back, ];
  3 -> 2 [color="#000000", style="dotted", ];
  2 -> 3 [color="#000000", style="dotted", ];
  ...........
  }

I need to modify it such that each list is reversed and the "," at the end of the list should be removed. For example, the output format should be like:

2 [shape=box, fillcolor="#FFEFD5", label="Decl n1"];

How do I approach this problem? Do I have to use any scripts? I am not very familiar with shell scripts.

Narmada
  • 3
  • 2

1 Answers1

0

Ideally you'd use something which is aware of the Dot syntax, allowing you to find and fix invalid syntax reliably. There is a Dot plugin for IDEA which you could try (use F2 to move to the next problem in the file). For very simple (but risky, since it's not syntax-aware) replacements you can use sed:

sed -i 's/, \]/]/' your-file

As for reversing with sed, the general pattern would be:

sed -i 's/\(first-part\)\(second-part\)/\2\1/' your-file
l0b0
  • 55,365
  • 30
  • 138
  • 223