PDA

View Full Version : Script writing in sed



BufordPants
August 20th, 2009, 05:15 PM
Can someone show me a script written using sed:

a)There is no trailing white space
b)Every comma is followed by one space
c) Every period is followed by two spaces
d)consecutive words are separated by one space
e)except for the above the file is otherwise unchanged

geirha
August 20th, 2009, 09:03 PM
Do it one step at a time, then combine all commands. An example with your a and d:

a) remove trailing whitespace, s/ *$//
d) squeze spaces s/ \{1,\}/ /g



sed 's/ *$//; s/ \{1,\}/ /g' file > newfile

DaithiF
August 21st, 2009, 10:26 AM
and just to round this out ... the other 2 pieces you wanted added here:

sed 's/ *$//; s/ \{1,\}/ /g; s/, */, /g; s/\. */. /g' somefile > newfile