In my constant pursuit of efficiency vis-a-vis laziness, I ended up writing this stream editor command.
I needed to transform this long list of constants in java into an HTML select tag. This served as a perfect opportunity to use sed.
Input: This comes from my file.
Input: This comes from my file.
public static final String SOME_CONSTANT_1 = "CST1"; public static final String SOME_CONSTANT_2 = "CST2";Output:
Here is the magical command.
sed -e 's/[[:space:]]\{1,\}/ /g' \ -e 's/.*g[[:space:]]\(.*\);/\1/g' \ -e 's/\(.*\)[[:space:]]*=[[:space:]]*"\(.*\)"/<option value="\2">\1<\/option>/g' \ fileName
- [1]: Replace multiple spaces/tabs [white spaces] in and around a line in a file with a single space.
- [2]: Get rid of unnecessary text
- [3]: Swap and format the output to HTML