0

I have a file that's all over the place and I'm sort of a neat freak, I do not feel comfortable sharing my file with a public site so ill say the file is called sync and looks like this

hh-hhhhhhhh-hhhhhhhh - sdgsg
hh-dgsdgdfgsgsdfgdgsdgsssd - dhhdhdh
fd-gdsg - dfsggs
dgssd-gdgsdg - fsdgsdg
dfgdg-sdgsgsdgsdgs - dghgdgs
dfsg-sdgdgdg - dsggg
sdgsdgdg-sgsgsdgsdggs;

I have done a

sed -i 's/-/;/p' sync

because i wanted a ; at the end of every line, I tried to use a special character with sed like

sed -i 's/\* - \*/;/p' sync

Is it possible to change everything after the last dash with nothing but a semi colon and have it be organized like this

 ggf-sdgsdfgfg;
 dg-gdfggdg-ggdfgdg;
 dggsdhds-hsdhshddgfdg;
 dgdhg-dggdggdgdgdfgdg-dfgg;
 fdgdgf-gdgfgd-fgdfgdgdgdgdgdg;
 dgdgdgd-gdfgdggdgdf-ggdfgdfgdggd;

1 Answers1

0

If your goal is to remove white spaces and put semicolon in the end of each line, you may try this:

sed 's/$\|;$/;/g' sync | sed 's/ //g' > output

Explanation: the first command replaces all [end of lines] OR [semicolon followed by end of line] by a single [semicolon]. The second sed command substitutes all [white spaces] by [nothing].

Hope it helps! :)

tk3
  • 990
  • 1
  • 13
  • 18