Reading file into variable, and losing line feeds
Nils Kassube wrote:
> Ray Parrish wrote:
>> I am interested in being able to read the contents of a text file
>> into a variable, complete with line feeds.
>> ray@RaysComputer:~/Bashscripts$ FileContents=`cat test.txt`
>> ray@RaysComputer:~/Bashscripts$ echo $FileContents
>> Line 1 Line 2 Line 3 Line 4 Line 5
>> Is there some trick to preserving the line feeds in the variable?
> The linefeeds are preserved but echo doesn't show them without quotes.
> Try this:
> echo "$FileContents"
Thank you Nils! I'm working on a multi-document, block oriented search,
and replace script to help me make broadcast changes across my web sites
all at one go.
None of the programmer's editors I installed would handle multi line
search, or replace terms, so I decided to write a program to do it for
me. Regexxer works fine if all you want to change is one line in all of
your files, but I need to make changes to multi line blocks of text like
adding a line in the middle of several other lines.
Now that I know the line feeds are still there, it will make coding the
script much easier.
Thanks again, Ray Parrish
The Future of Technology.
Ray's Links, a variety of links to usefull things, and articles by Ray.
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
ubuntu-users mailing list
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users