[CentOS] Variable assigned to grep output - missing letter n!

Devin Reade gdr at gno.org
Wed Jul 20 22:11:02 UTC 2011


--On Wednesday, July 20, 2011 02:53:06 PM -0500 Sean Carolan
<scarolan at gmail.com> wrote:

> Now the next
> question would be, how can I include the \n characters in my variable
> string, without fudging with $IFS?

Can you describe, functionally and a bit higher level, what you're
trying to achieve?  Is myvar supposed to contain the entire file
content if the file contains "lorem", or just any lines containing
lorem complete with newline, or are you expecting some other form 
of delimiter, or what?  Also of interest is what you're going to do
with myvar after the fact (write it out, do a replacement, whatever).

For example, if you're trying to do some form of processing that
only considers lines containing lorem, other tools might give
a cleaner, faster, and more maintainable result:

   #! /usr/bin/perl
   use taint;
   use strict;

   while (<>) {
      if (m,lorem,) {
         # do something with $_
      }
   }

(No, I don't advocate perl for everything, but knowing more about the
problem can
help in determining a suitable solution.)

Devin



More information about the CentOS mailing list