First post. I'm just getting to grips with sed.
I've learned the basic substitution commands.
But I'm a bit stuck on this problem.
I'm running through some python files to convert syntax from Gtk2 to Gtk3 notation.
Consider a simple line of python like this ..
import gtk, pango, gtksourceview2, gobject
The terms might be in any order ...
e.g.
import gtk, gobject, pango, gtksourceview2
import gtk, pango, gobject, gtksourceview2, gobject
or even some terms left out in some input files ...
import gtk, gobject
I would like to see the output from sed as single line expressions ...
import gtk
import pango
import gtksourceview2
import gobject
and from there I can run through these single line expressions again to finally convert to Gtk3.
I've read how to use the "^, "|" , "&" and "$" operators in sed ...
sed -r 's/^import.(gtk$|pango$|gtksourceview2$|gobject$)/&\n/g' input.py > output.py
but I'm not there yet.
....
Here is a compressed code (Gtk2) example
import gtk, pango, gtksourceview2, gobject
import sys, os, re, glob, subprocess, webbrowser, base64, cgi, urllib2, shutil, time, pgsc_spellcheck
This is how the final (Gtk3) output code should look.
from gi.repository import Gtk
from gi.repository import Pango
from gi.repository import GtkSource
from gi.repository import GObject
import sys
import os
import re
import glob
import subprocess
import webbrowser
import base64
import cgi
import urllib2
import shutil
import pgsc_spellcheck
....
So the question as in title .. how to parse the line ...
import a, b, c, d, e
... (module names in any random order and some might be missing) into line-by-line expressions?
Thanks.