LINUX-SED question

April 30, 2009 at 14:26:16
Specs: Windows XP
How can I edit a file doing the following:
1- join all lines that are not empty
2- change the empty line to contain just a semicolon ; as an SQL statement terminator
example
select a,b_
col1 from bla

select d, prod_i
dent from prod where p
rod_ident = 10

to be
select a,b_col1 from bla
;
select d, prod_ident from prod where prod_ident = 10
;

Thanks!


See More: LINUX-SED question

Report •


#1
May 1, 2009 at 23:18:50
This works for only the GNU sed (i.e. Linux):

sed -e 's/^$/;/g' \
  -n -e '
H
$ {
  x
  s/\n//g
  s/;/\n;\n/g
  p
}
' datafile

Since the entire file is read into sed's buffer space, this script works on small files.


Report •
Related Solutions


Ask Question