LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-21-2009, 04:01 PM   #1
scott_audio
Member
 
Registered: Jul 2009
Location: USA
Distribution: openSUSE 11.1, Kubuntu 9.04
Posts: 35

Rep: Reputation: 16
Well done is better than well sed


First, what I have, works... so I'm not asking someone to do a bunch of work 'for me'. I'm just looking to improve what I have, and learn something from seeing it done right.

I volunteered to help find a solution for a group where the goal was to extract all bible references that are enclosed consistently in parentheses from a given text document, grab the referenced verse or range of verses from a database and generate a list, so the actual verse content is there, and not just the reference.

To grab the scripture, I used Chip Chapin's bible-kjv, which does not like roman numerals, and prefers queries to NOT have any spaces (2Corinthians2:1 instead of II Corinthians 2:1).

Code:
bible -f -l80 2Corinthians2:1
Above example would generate formatted (-f) text at 80 characters.

As can be seen in my newbie script, I hack away at the text, extracting all the references enclosed in parentheses, but only if it's got a colon preceded by a number, removes any semi-colons, removes the spaces, etc. finally generating a double-spaced list of scriptures with a place to put a check mark or whatever. bible-kjv is ok with commas.

I just can't seem to figure out how to get around directing to multiple files and using so many seds... I am a newbie, and what I have works fine, just looking to do it better, and learn, any ideas?

Code:
cat $1 | grep \( \
        | cut -d ')' -f 1 - \ 
        | cut -d '(' -f 2 - \
        | grep \[0-9]\: \
        | sed 's/cf./,/g' \
        | tr \, \\n \
        | sed 's/and//g' \
        | sed 's/ //g' \
        | sed 's/\;//g' \
        | sed 's/^III/3/g' \
        | sed 's/^II/2/g' \
        | sed 's/^I/1/g' \
        | sed 's/Philemon/Philemon1:/' \
        | sed 's/Obadiah/Obadiah1:/' \
        | sed 's/^2John/2John1:/' \
        | sed 's/^3John/3John1:/' \
        | sed 's/^Jude/Jude1:/' \
        > ref.1
cat ref.1 | while read line; do
        bible -f -l80 $line >> ref.2
done
cat ref.2 | sed 's/^/\[_____\] /' | sed G > ref.rtf
Thanks for looking.
-Scott
 
Old 08-21-2009, 04:06 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
There are a million ways to do the same thing in terms of general improvement, I'd probably be doing all of that as an awk script for example, but for what you're specifically asking, you can do multiple seds easily enough... "sed -e 's/a/b/g' -e 's/c/d/g'" and so on. As for the files... why are you using that ref.1 file at all? After all those pipes, why not just use another one?? likewise for ref.2 really, you can pipe after the done to take the entire output as a single stream.
 
Old 08-21-2009, 04:17 PM   #3
scott_audio
Member
 
Registered: Jul 2009
Location: USA
Distribution: openSUSE 11.1, Kubuntu 9.04
Posts: 35

Original Poster
Rep: Reputation: 16
I guess I was thinking I wanted to be able to look at the individual files to check the formatting - I have no idea what I'm doing is the best answer I'll try a single sed like you demonstrated and lose the pipes, and read up more on awk as well, thanks, Chris.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed sycamorex Linux - General 3 07-06-2007 08:18 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 12:36 PM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 01:34 AM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-04-2005 12:00 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM


All times are GMT -5. The time now is 11:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration