Computing.Net > Forums > Programming > LINUX-SED question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

LINUX-SED question

Reply to Message Icon

Name: Sam2020
Date: April 30, 2009 at 14:26:16 Pacific
OS: Windows XP
Subcategory: General
Comment:

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!



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: May 1, 2009 at 23:18:50 Pacific
Reply:

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.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: LINUX-SED question

variable substitution with sed www.computing.net/answers/programming/variable-substitution-with-sed-/16669.html

Running C on Linux www.computing.net/answers/programming/running-c-on-linux/10406.html

Best GUI lib. best IDE in linux. www.computing.net/answers/programming/best-gui-lib-best-ide-in-linux/6913.html