Re: sed and Auuuugghh!!!!



On 2006-12-02, Joshua Whalen wrote:
Here's one that I'm almost certain will
result in my having to scrape egg off my
face for an age, because I'm sure the
answer is trivially obvious, and I'm just
too stressed out and deadlined in to see it.
Here goes:

I'm trying to write a program to manage a
mailing list. The mailing list uses carriage
returns as delimiters, but the user's computer
uses quotes and commas. So I'm trying to change
this:

bogus@xxxxxxxxx
sugob@xxxxxxxxx
gusbog@xxxxxxxxx
gobsu@xxxxxxxxx
gobus@xxxxxxxxx
spambot@xxxxxxxxxxxxx
tobmaps@xxxxxxxxxxxxx
botsmap@xxxxxxxxxxxxx
scamad@xxxxxxxxxx
damcas@xxxxxxxxxx
casmad@xxxxxxxxxx
bogus@xxxxxxxxx
sugob@xxxxxxxxx
gusbog@xxxxxxxxx
gobsu@xxxxxxxxx
gobus@xxxxxxxxx
spambot@xxxxxxxxxxxxx
tobmaps@xxxxxxxxxxxxx
botsmap@xxxxxxxxxxxxx
scamad@xxxxxxxxxx
damcas@xxxxxxxxxx
casmad@xxxxxxxxxx
bogus@xxxxxxxxx
sugob@xxxxxxxxx
gusbog@xxxxxxxxx
gobsu@xxxxxxxxx
gobus@xxxxxxxxx
spambot@xxxxxxxxxxxxx
tobmaps@xxxxxxxxxxxxx
botsmap@xxxxxxxxxxxxx
scamad@xxxxxxxxxx
damcas@xxxxxxxxxx


into this:

"bogus@xxxxxxxxx", "sugob@xxxxxxxxx", "gusbog@xxxxxxxxx", "gobsu@xxxxxxxxx", "gobus@xxxxxxxxx", "spambot@xxxxxxxxxxxxx", "tobmaps@xxxxxxxxxxxxx", "botsmap@xxxxxxxxxxxxx", "scamad@xxxxxxxxxx", "damcas@xxxxxxxxxx", "casmad@xxxxxxxxxx", "bogus@xxxxxxxxx", "sugob@xxxxxxxxx", "gusbog@xxxxxxxxx", "gobsu@xxxxxxxxx", "gobus@xxxxxxxxx", "spambot@xxxxxxxxxxxxx", "tobmaps@xxxxxxxxxxxxx", "botsmap@xxxxxxxxxxxxx", "scamad@xxxxxxxxxx", "damcas@xxxxxxxxxx", "casmad@xxxxxxxxxx", "bogus@xxxxxxxxx", "sugob@xxxxxxxxx", "gusbog@xxxxxxxxx", "gobsu@xxxxxxxxx", "gobus@xxxxxxxxx", "spambot@xxxxxxxxxxxxx", "tobmaps@xxxxxxxxxxxxx", "botsmap@xxxxxxxxxxxxx", "scamad@xxxxxxxxxx", "damcas@xxxxxxxxxx", "casmad@xxxxxxxxxx", "bogus@xxxxxxxxx", "sugob@xxxxxxxxx", "gusbog@xxxxxxxxx", "gobsu@xxxxxxxxx", "gobus@xxxxxxxxx", "spambot@xxxxxxxxxxxxx", "tobmaps@xxxxxxxxxxxxx", "botsmap@xxxxxxxxxxxxx", "scamad@xxxxxxxxxx", "damcas@xxxxxxxxxx", "casmad@xxxxxxxxxx"

the script I'm using looks like this:

#!/bin/sh
sed 'N;s/\n/", "/;P;D;' ~/Desktop/bogus.list >~/Desktop/output.list

and produces this:

bogus@xxxxxxxxx", "sugob@xxxxxxxxx
....
gobsu@xxxxxxxxx", "gobus@xxxxxxxxx
spambot@xxxxxxxxxxxxx", "tobmaps@xxxxxxxxxxxxx
botsmap@xxxxxxxxxxxxx", "scamad@xxxxxxxxxx
damcas@xxxxxxxxxx", "casmad@xxxxxxxxxx


what exactly am I doing wrong, and how can I fix it?

awk 'NR > 1 { printf "," }
{ printf "\"%s\"", $0 }
END { print "" }
' "$HOME/Desktop/bogus.list" > "$HOME/Desktop/output.list"

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.



Relevant Pages

  • sed and Auuuugghh!!!!
    ... result in my having to scrape egg off my ... face for an age, because I'm sure the ... the script I'm using looks like this: ... what exactly am I doing wrong, and how can I fix it? ...
    (comp.unix.shell)
  • Re: Determining caller for a shell function
    ... Chris F.A. Johnson, author ... Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ...
    (comp.unix.shell)