[PLUG-Devel] Process text records
der.hans
PLUG at LuftHans.com
Sat Nov 17 13:50:46 MST 2007
Am 17. Nov, 2007 schwätzte Joey Prestia so:
> I am having problems trying to pull paragraphs out of a text file in
> bash. The text file is several hundred pages long and consists of
> paragraphs with newline characters. And the only thing I can use for a
> field separator is a blank line any ideas on how I be able to accomplish
> this? I have tried using sed and tr to process the file and basically
> tried this:
You're trying to pull the paragraphs out as a single entity?
> #!/bin/bash
> sed 's/^$/@/g' text > text.out
> for i in `seq 1 100` ; do
> cut -d@ -f$i text.out > string
> file=`cat string`
> echo $file | mail -s "Your data" user at domain.com
> done
>
> because of the newline characters I get bad results. I have been using
> README file in /usr/share/doc to try to get this right but the newlines
> throw the results wacky if I tr them out and if I leave them in the
> fields come up wrong because of the \n characters.
I'm not sure why you're trying to pull the paragraphs apart or what you're
trying to do with them, but maybe the following code will help you.
( para=''
nl=$'\n'
head -10 /usr/share/doc/vim/README.Debian | while read line; do
echo $line | grep -q -- '^$'
grepres=$?
if [ 0 -eq $grepres ] ; then
echo "<$para>"
echo "This line intentionally left non-blank."
para=''
else
# echo "<<$line>>"
para="${para:+${para}${nl}}${line}"
fi
done )
<VIM for Debian
--------------->
This line intentionally left non-blank.
<1. The current Debian VIM scripts policy can be found in
/usr/share/doc/vim
and <http://yacoob.dnsalias.net/sakwa/vim-policy.txt>.>
This line intentionally left non-blank.
<2. Before reporting bugs, check if the bug also exists if you run vim
with "vim -u NONE -U NONE". If not, make sure that the "bug" is not
a result of a setting in your ~/.vimrc before reporting it.>
This line intentionally left non-blank.
I put it all in a subshell with the parens to keep the script from
muddying up my login shell.
ciao,
der.hans
--
# https://www.LuftHans.com/ http://www.CiscoLearning.org/
# "We should not be building surveillance technology into standards.
# Law enforcement was not supposed to be easy.
# Where it is easy, it's called a police state." -- Jeff Schiller
More information about the PLUG-devel
mailing list