Sponsored Content
Top Forums Shell Programming and Scripting replace string in file.1 with line from file.2 Post 302315138 by ccox85 on Monday 11th of May 2009 03:56:27 PM
Old 05-11-2009
replace string in file.1 with line from file.2

Hello all, the title makes this sound simple, and maybe it should be.

This is by code:
Code:
#!/bin/sh
cp ch25.txt ch25.fn.tex
n=`grep -c '^\[' ch25_footnotes.txt`

for i in {1..$n}
do
        `grep '^\[$i\]' ch25_footnotes.txt > temp`
        r=`awk -F] '{print $2}' temp`
        `sed 's/\[$i\]/\\footnote{$r}/' ch25.fn.tex`
done

This is what I am trying to do. I have a file like this:
Quote:
First there was nothing. Then there was Calvin[1].
That contains a body of text with footnotes markers, that are of exactly that format [i]. Square brackets are not used otherwise in the text... at least no patters of the form [integer] exist except for footnote markers.

I have a another file of the footnote text, like this
Quote:
[1] A memorable quote from Bill Waterson's Calvin and Hobbes.
What that code I wrote is attempting to do is:
  1. Create a copy of the body text to mess with.
  2. Count the number of footnotes that exist.
  3. Initiate a For loop that will generate an $i for every integer up to $n, the number of footnotes.
  4. grep the line starting with [$i] and save stick it into a temp file.
  5. use awk to grab only the text portion of the footnote (skipping the [$i] number at the beginning of the line) and store that in variable r.
  6. Finally, search the main file for the [$i] marker and add the footnote, alone with \footnote{} markup for latex.
  7. Repeat hundreds of times (-;

I am not all that great with scripting, but this is my thought process and what I have tried. Right now... nothing happens. I execute the script, and it just hangs, and I have to break the script.

In case you are wondering, I am just trying to typeset Marx's Das Kapital for posterity and easier reading. I do not plan on printing or distributing... just taking a freely available reading material and making it pretty.

Thank you!

Last edited by ccox85; 05-11-2009 at 05:28 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how can search a String in one text file and replace the whole line in another file

i am very new to UNIX plz help me in this scenario i have two text files as below file1.txt name=Rajakumar. Discipline=Electronics and communication. Designation=software Engineer. file2.txt name=Kannan. Discipline=Mechanical. Designation=CADD Design Engineer. ... (6 Replies)
Discussion started by: kkraja
6 Replies

2. Shell Programming and Scripting

Replace string in a file within a range of line

Hi, I want to replace the srting '; with ABCD'; in a file from line 1 to line 65. Is there any single command to do it without using awk Thanks for quick reply https://www.unix.com/images/misc/progress.gif (3 Replies)
Discussion started by: tosattam
3 Replies

3. Shell Programming and Scripting

To trim Certain field in a line of a file and replace the new string in that position

To trim 3rd field in for all the lines of a file and replace the modified string in that particular field. For example i have a file called Temp.txt having content Temp.txt ----------------- 100,234,M1234 400,234,K1734 300,345,T3456 ---------------- So the modified file output should... (4 Replies)
Discussion started by: rpadhi
4 Replies

4. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

5. Shell Programming and Scripting

Replace line in file with line in another file based on matching string

Hi I am not the best scripter in the world and have run into a issue which you might be able to guide me on... I have two files. File1 : A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB File2: C345,... (5 Replies)
Discussion started by: luckycharm
5 Replies

6. Shell Programming and Scripting

sed or awk to replace a value in a certain line from another file containing a string

Hi experts, In my text file I have the following alot of lines like below. input.k is as follows. 2684717 -194.7050476 64.2345581 150.6500092 0 0 2684718 -213.1575623 62.7032242 150.6500092 0 0 *INCLUDE $# filename... (3 Replies)
Discussion started by: hamnsan
3 Replies

7. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

8. Shell Programming and Scripting

Replace a string with each line from another file repeatedly

I don't know if it's been asked before but seems i gave up seeking. i have 2 files : file1.txt Monday XXXX Tuesday XXXX XXXX Wednesday Thursday XXXX XXXX is in every lines of file1.txt and i want to replace them with each line in file2.txt: home school cinema so output file is: ... (19 Replies)
Discussion started by: perseous
19 Replies

9. Shell Programming and Scripting

Replace line in file with line in another file based on matching string

HI Can any one guide me how to achieve this task. I have 2 files env.txt #Configuration.Properties values identity_server_url = http://identity.test-hit.com:9783/identity/service/user/register randon_password_length = 6 attachment_file_path = /pass/temp/attachments/... (1 Reply)
Discussion started by: nikilbr86
1 Replies

10. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies
MKD-EXTENSIONS(7)				       BSD Miscellaneous Information Manual					 MKD-EXTENSIONS(7)

NAME
mkd-extensions -- Extensions to the Markdown text formatting syntax DESCRIPTION
This version of markdown has been extended in a few ways by extending existing markup, creating new markup from scratch, and borrowing markup from other markup languages. Image dimensions Markdown embedded images have been extended to allow specifying the dimensions of the image by adding a new argument =/height/x/width/ to the link description. The new image syntax is ![alt text](image =/height/x/width/ "title") pseudo-protocols Five pseudo-protocols have been added to links id: The alt text is marked up and written to the output, wrapped with <a id=id> and </a>. class: The alt text is marked up and written to the output, wrapped with <span class=class> and </span>. raw: The title is written -- with no further processing -- to the output. The alt text is discarded. abbr: The alt text is marked up and written to the output, wrapped with <abbr title=abbr> and </abbr>. lang: The alt text s marked up and written to the output, wrapped with <span lang=lang> and </span>. Pandoc headers The markdown source document can have a 3-line Pandoc header in the format of % title % author(s) % date which will be made available to the mkd_doc_title(), mkd_doc_author(), and mkd_doc_date() functions. Definition lists A definition list item is defined as =tag= description (that is a =, followed by text, another =, a newline, 4 spaces of intent, and then more text.) Alternatively, definition list items are defined as tag : description (This is the format that PHP Markdown Extra uses.) embedded stylesheets Stylesheets may be defined and modified in a <style> block. A style block is parsed like any other block level html; <style> starting on column 1, raw html (or, in this case, css) following it, and either ending with a </style> at the end of the line or a </style> at the begin- ning of a subsequent line. Be warned that style blocks work like footnote links -- no matter where you define them they are valid for the entire document. relaxed emphasis The rules for emphasis are changed so that a single _ will not count as a emphasis character if it's in the middle of a word. This is pri- marily for documenting code, if you don't wish to have to backquote all code references. alpha lists Alphabetic lists (like regular numeric lists, but with alphabetic items) are supported. So: a. this b. is c. an alphabetic d. list will produce: <ol type=a> <li>this</li> <li>is</li> <li>an alphabetic</li> <li>list</li> </ol> tables PHP Markdown Extra tables are supported; input of the form header|header ------|------ text | text will produce: <table> <thead> <tr> <th>header</th> <th>header</th> </tr> </thead> <tbody> <tr> <td>text</td> <td>text</td> </tr> </tbody> </table> The dashed line can also contain : characters for formatting; if a : is at the start of a column, it tells discount to align the cell con- tents to the left; if it's at the end, it aligns right, and if there's one at the start and at the end, it centers. strikethrough A strikethrough syntax is supported in much the same way that ` is used to define a section of code. If you enclose text with two or more tildes, such as ~~erased text~~ it will be written as <del>erased text</del>. Like code sections, you may use as many ~ as you want, but there must be as many starting tildes as closing tildes. markdown extra-style footnotes PHP Markdown Extra footnotes are supported. If a footnote link begins with a ^, the first use of that footnote will generate a link down to the bottom of the rendered document, which will contain a numbered footnote with a link back to where the footnote was called. AUTHOR
David Parsons http://www.pell.portland.or.us/~orc/ SEE ALSO
markdown(1), markdown(3), mkd-callbacks(3), mkd-functions(3), mkd-line(3). http://daringfireball.net/projects/markdown http://michelf.com/projects/php-markdown MASTODON
Dec 22, 2007 MASTODON
All times are GMT -4. The time now is 07:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy