Re: sed file processing?
Jude DaShiell <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
This action is happening on a free-bsd system and I don't know if eol markers are put on ends of lines in native format. I am using spamassassin and sending spam to probably-spam for further action. Aside from what the program learns or fails to learn, the script searches down through probably-spam and finds all of the From: lines and saves those to a file called rf. What I'm going to do with sed is to do a command like sed -e "%s/^/blacklist-/ rf <cr> that should tack blacklist- onto the beginning of every line in rf. Once that's done, ~/.spamassassin/user_prefs needs a little concatenation of the file called rf. Once that's done I delete the file called rf and a .logout script runs sa-learn --spam then deletes all email in probably-spam. Last time I checked, 794 unique entries in user_prefs that are blacklisted. This has started in October 2013 so that will give you an idea as to the spam volume around here. I figure the more I can automate the fewer mistakes happen and sed is golden in terms of these capabilities! I could probably have automated more in this work flow with sed than was done, but I figured at least this operation might have been something sed could handle well and it appears sed will do it better than I expected. On Fri, 14 Feb 2014, [email protected] wrote: > That was a great question. > > As in previous response, if the file is totally empty, sed tries to read the first line, fails, and exits. > > If the file has one line, but no EOL marker, sed reads the line, but somehow figures out NOT to an EOL marker when it outputs the pattern space. > > Here is the normal case with EOL marker: > > $ echo "X" | sed "s/X/Y/" > Y > $ > > Here is the case with EOL marker missing: > > $ echo -n "X" | sed "s/X/Y/" > Y$ > > Are you wanting sed to take no action if no EOL marker on single line? > > Daniel > > ---In [email protected], <dave_br@...> wrote: > > On Fri, 14 Feb 2014 06:05:12 -0500 (EST), Jude DaShiell > <jdashiel@... mailto:jdashiel@...> wrote: > > > Is it within sed's logical capacity to check a file and only do a command > > on that file if it has at least one line of text in it? For what I'm > > trying to do with a script, if the file has zero lines it should not have > > anything done to it. > > If a file has zero lines sed can't do anything on it anyway, since by > definition sed works on input lines. > > $ touch a > $ sed 's/^/foobar/' a > $ > > Pleae note that a file that is NOT 0 bytes in size is neither an empty file > nor one with no lines of text. > > -- > D. > > jude <[email protected]>