Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Could you be a bit more specific please? How about posting some actual examples of the kind of text that you would be handling, along with the format of the desired output?
In any case, I'd guess that the most likely procedure would be to use a tool like grep, sed, or awk to extract the text you want from one file, store it in a variable, then use sed or awk again to insert the contents into the second one. But the devil's in the details, so to speak.
Last edited by David the H.; 04-28-2010 at 12:14 PM.
Reason: Added follow-up paragraph.
I'm not sure if this is along the lines of what you are asking about; but I once created a SED script to take the output of the "file" command and produce a script to rename files, adding the extensions, based on the mime database. The SED program was over 800 lines long. I massaged the mime database to a convenient form, using SED and vim, and then used a SED command to create the final SED program. Running the final SED program would result in a bash script that I would run to rename the files (after inspection). This was for a person who recovered files from a corrupt filesystem and was left with thousands of file names without extensions.
Whether you use sed, awk or perl, regular expressions need to be precisely described to handle your exact situation and to avoid missed patterns or false positives. As a result, you need to be more exact in defining your question, and include actual lines of input, and the output you want to produce.
Chapter1
Performing a kidney removal on myself without anesthetics.
Chapter1
storyChanger.txt >
How to Eat Yourself or Someone Else
Chapter1
If you are eating yourself, start by cutting off your foot.
Chapter1
****
What's in between chapter1 of storyChanger.txt should replace what's in between chapter1 of operation.txt .
This is just for my personal practice. I keep coming back to GUI even though I want to go as long as possible using CUI except for when I have to use GUI like watch a movie. It is some of these commands or tasks that get in my way.
Look at selecting line ranges in sed. e.g. /Chapter1/,/Chapter1/
also look at the read command. Rather than using a single sed command, perhaps use sed to extract the replacement test, and extract it to a temporary file (or a pipe) and a second sed command to locate the range of lines in the original text, and read the lines from the temporary file.
If you do do something like this, perhaps using xml markup for both files, would be a better plan.
I'd start by figuring out how to match the text you want to change in both files. Check out the sed faq for some useful tips on handling common situations.
When you've made some progress there we can see about building a script around them to copy the text between them.
BTW, please use [code][/code] tags when posting any blocks of text where the formatting is important (script code and file contents). It helps keep things readable. Thanks.
For real documents on a large project, you would probably have a text file for each chapter and use a text editor to make your changes. Vim's ed commands are nearly identical to using sed.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.