Re: sed and Auuuugghh!!!!
- From: "Chris F.A. Johnson" <cfajohnson@xxxxxxxxx>
- Date: Fri, 1 Dec 2006 22:25:22 -0500
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
.
- References:
- sed and Auuuugghh!!!!
- From: Joshua Whalen
- sed and Auuuugghh!!!!
- Prev by Date: help : cat help | grep '^99\d' don't work
- Next by Date: Re: help : cat help | grep '^99\d' don't work
- Previous by thread: sed and Auuuugghh!!!!
- Next by thread: Re: sed and Auuuugghh!!!!
- Index(es):
Relevant Pages
|