Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-30-2007, 10:20 AM
|
#1
|
|
LQ Newbie
Registered: Jul 2006
Posts: 18
Rep:
|
Batch search-and-replace?
I have several text documents that have citations inserted using the Windows program Reference Manager. I would like to replace these citations with BibTeX citations so that the documents can be processed in LaTeX. Because there are around a hundred different citations, I am looking for an easy way to find all the citations in one format and replace them with citations in the other format. It would be quite easy to prepare a list of equivalent citations in a spreadsheet. Is there a good way of doing this? I'm not quite sure what program I am looking for.
Thanks
|
|
|
|
08-30-2007, 10:22 AM
|
#2
|
|
Member
Registered: Aug 2007
Location: The Netherlands
Distribution: Fedora 7 x86_64
Posts: 119
Rep:
|
Tried using an editor like gedit, geany, SCiTE, scribes, kates with search and replace yet? If that doesn't work you can try doing it with regexxer with regular expressions.
|
|
|
|
08-30-2007, 11:38 AM
|
#3
|
|
LQ Newbie
Registered: Jul 2006
Posts: 18
Original Poster
Rep:
|
Thanks for the reply.
Essentially, what I have at the moment is two lists: a list of Reference Manager citations and a list of corresponding BibTeX citations (or one list made up of pairs of citations). I could type each individual pair into any search-and-replace facility, but it would take hours because there are around a hundred pairs. Plus it would only replace them in one document. I'm looking for a way of replacing the citations that does not involve typing them all in to search-and-replace boxes and then having to go through the same laborious process for every single document. Do any of the programs you mentioned allow you to supply the program with a long list of terms and the terms you want to replace them with?
Thanks again.
|
|
|
|
08-30-2007, 01:55 PM
|
#4
|
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,797
|
Suppose you want to replace all instances of "dog" with "horse". Put all the files in one directory, and do this---in that directory:
Code:
for i in *; do sed -i 's/dog/horse/g' $i; done
This will process every file in the directory.
To be more selective, you could--e.g.-- process all the .doc files thusly:
Code:
for i in *.doc; do sed -i 's/dog/horse/g' $i; done
To put the modified data in new files:
Code:
for i in *;do sed 's/dog/horse/g' $i > new$i; done
(takes data from "name", modifies it, and writes to "newname".
Last edited by pixellany; 08-30-2007 at 01:59 PM.
|
|
|
|
08-31-2007, 07:21 AM
|
#5
|
|
LQ Newbie
Registered: Jul 2006
Posts: 18
Original Poster
Rep:
|
I would still have to do that about a hundred times:
Code:
for i in *; do sed -i 's/dog/horse/g' $i; done
for i in *; do sed -i 's/cat/gerbil/g' $i; done
for i in *; do sed -i 's/mouse/iguana/g' $i; done
...
and so on to change a hundred animals into a hundred different ones.
|
|
|
|
08-31-2007, 07:42 AM
|
#6
|
|
Member
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451
Rep:
|
Please post the format of both citations with examples. If it is indeed _one format_ it should be possible with sed regexp to change the one format into another.
|
|
|
|
08-31-2007, 11:12 AM
|
#7
|
|
LQ Newbie
Registered: Jul 2006
Posts: 18
Original Poster
Rep:
|
The first format looks like
The second format looks like
Although they are not always such good matches, such as:
Code:
Högberg, 2001 27 /id
Jones, 1997 12 /id
van der Heijden, 1998 32 /id
are
Code:
Hogberg2001
Jones1997b
Heijden1998
which is why I am not sure sed is quite the right tool.
|
|
|
|
08-31-2007, 11:25 AM
|
#8
|
|
Member
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451
Rep:
|
Hmm, should not be so hard. The only thing I wonder is where the b comes from in: Jones1997b
I think the sed regexp might look like:
Code:
sed 's/.*[ ]\{0,1\}\([^ ]*,[0-9]*\)\s.*$/\1/g'
I can't test it at the moment ...
Although if you want to run it on the whole text it would need to only match citations.
Last edited by muha; 08-31-2007 at 11:32 AM.
|
|
|
|
08-31-2007, 12:08 PM
|
#9
|
|
LQ Newbie
Registered: Jul 2006
Posts: 18
Original Poster
Rep:
|
The 'b' is because there are already another two Jones references from 1997 (Jones1997 and Jones1997a) in that database. There is no real way of matching them up to the ones in the other database using regular expressions, because there is no real connection between them. I can export a complete list of citations from each database and pair them up in a spreadsheet (CSV file, whatever) quite easily, so if I could just feed that data into a program that would replace all the text in the first column with the corresponding text in the second column (without any use of regular expressions), it would give exactly the right result.
|
|
|
|
08-31-2007, 12:22 PM
|
#10
|
|
Member
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451
Rep:
|
Quote:
Originally Posted by jkh107
so if I could just feed that data into a program that would replace all the text in the first column with the corresponding text in the second column
|
You can do that in your spreadsheet program too.
I don't know if you're interested but sed can count as well. It's a little-bit more advanced but you can this sort of stuff with sed. For people interested in more: http://www.linuxquestions.org/bookmarks/tags/sed
|
|
|
|
09-02-2007, 04:11 AM
|
#11
|
|
LQ Newbie
Registered: Jul 2006
Posts: 18
Original Poster
Rep:
|
How would I use a spreadsheet program for this?
|
|
|
|
09-02-2007, 06:18 AM
|
#12
|
|
Senior Member
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian Testing; OpenSuSE 12.1; Fedora 17
Posts: 1,541
Rep: 
|
I think 'tr', man tr, would work for you. It's a search and replace utility that translates by regular expressions.
|
|
|
|
09-02-2007, 07:26 AM
|
#13
|
|
Member
Registered: Aug 2007
Posts: 92
Rep:
|
awk (or gawk) is by far the best stream editor.
It is available for both UNIX and windows.
Takes a bit of learning though.
|
|
|
|
09-02-2007, 10:03 AM
|
#14
|
|
LQ Newbie
Registered: Jul 2006
Posts: 18
Original Poster
Rep:
|
Looks like sed might do the job if I use a text file containing a list of all the substitutions. Thanks for all the suggestions.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:52 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|