Sponsored Content
Top Forums Shell Programming and Scripting Replace string of a file with a string of another file for matches using grep,sed,awk Post 303026462 by RudiC on Wednesday 28th of November 2018 06:44:43 AM
Old 11-28-2018
After reading your request several times I have a hard time precisely understanding what you need. Amongst other questions it's unclear what be
- the point you're stuck at with your attempts to a solution, and what you want changed.

- the structure of files under /tmp.
- the structure of entries to be modified.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed, grep, awk, regex -- extracting a matched substring from a file/string

Ok, I'm stumped and can't seem to find relevant info. (I'm not even sure, I might have asked something similar before.): I'm trying to use shell scripting/UNIX commands to extract URLs from a fairly large web page, with a view to ultimately wrapping this in PHP with exec() and including the... (2 Replies)
Discussion started by: ropers
2 Replies

2. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

3. Shell Programming and Scripting

How to find a certain string in a file and replace it with a value from another file using sed/awk?

Hi Everyone, I am new to this forum and new to sed/awk programming too !! I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column. file 1: (assert (=... (21 Replies)
Discussion started by: paramad
21 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 (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 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

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

8. Shell Programming and Scripting

Help with Passing the Output of grep to sed command - to find and replace a string in a file.

I have a file example.txt as follows :SomeTextGoesHere $$TODAY_DT=20140818 $$TODAY_DT=20140818 $$TODAY_DT=20140818I need to automatically update the date (20140818) in the above file, by getting the new date as argument, using a shell script. (It would even be better if I could pass... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

9. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

10. Shell Programming and Scripting

Replace all string matches in file with unique random number

Hello Take this file... Test01 Ref test Version 01 Test02 Ref test Version 02 Test66 Ref test Version 66 Test99 Ref test Version 99 I want to substitute every occurrence of Test{2} with a unique random number, so for example, if I was using sed, substitution would be something... (1 Reply)
Discussion started by: funkman
1 Replies
btool_faq(3)							      btparse							      btool_faq(3)

NAME
btool_faq - Frequently-Asked Questions about btparse and Text::BibTeX DESCRIPTION
This document attempts to address questions that I have been asked several times, and are easy to answer -- but not by perusing the documentation. For various reasons, the answers tend to be thinly distributed across several man pages, making it difficult to figure out what's going on. Hence, this man page will attempt to tie together various strands of thought, providing quick, focused, "How do I do X?" answers as opposed to lengthy descriptions of the capabilities and conventions of the btOOL libraries. PERL LIBRARY
This section covers questions that users of "Text::BibTeX", the Perl component of btOOL, have asked. Why aren't the BibTeX "month" macros defined? Because they're bibliography-specific, and "Text::BibTeX" by default doesn't impose any assumptions about a particular type of database or data-processing domain on your entries. The problem arises when you parse entries from a file, say foo.bib that quite sensibly use the month macros ("jan", "feb", etc.) provided by the BibTeX standard style files: $bibfile = new Text::BibTeX::File 'foo.bib' # open file or die "foo.bib: $! "; $entry = new Text::BibTeX::Entry $bibfile; # parse first entry Using this code, you might get an "undefined macro" warning for every entry parsed from foo.bib. Apart from the superficial annoyance of all those warning messages, the undefined macros are expanded as empty strings, meaning you lose any information about them---not good. You could always kludge it and forcibly define the month macros yourself. Prior to release 0.30, this had to be done by parsing a set of fake entries, but now "Text::BibTeX" provides a direct interface to the underlying macro table. You could just do this before parsing any entries: use Text::BibTeX qw(:macrosubs); # ... my %month = (jan => 'January', feb => 'February', ... ); add_macro_text ($macro, $value) while (($macro, $value) = each %month); But there's a better way that's more in keeping with how things are done under BibTeX (where default macros are defined in the style file): use "Text::BibTeX"'s object-oriented analogue to style files, called structure modules. "Text::BibTeX" provides a structure module, "Text::BibTeX::Bib", that (partially) emulates the standard style files of BibTeX 0.99, including the definition of month macros. Structure modules are specified on a per-file basis by using the "set_structure" method on a "Text::BibTeX::File" object. It's quite simple to tell "Text::BibTeX" that entries from $bibfile are expected to conform to the "Bib" structure (which is implemented by the "Text::BibTeX::Bib" module, but you don't really need to know that): $bibfile = new Text::BibTeX::File 'foo.bib' or die "foo.bib: $! "; $bibfile->set_structure ('Bib'); You probably shouldn't hardcode the name of a particular structure in your programs, though, as there will eventually be a multitude of structure modules to choose from (just as there are a multitude of BibTeX style files to choose from). My preferred approach is to make the structure a command-line option which defaults to "Bib" (since that's the only structure actually implemented as of this writing). How do I append to a BibTeX file? Just open it in append mode, and write entries to it as usual. Remember, a "Text::BibTeX::File" object is mainly a wrapper around an "IO::File" object, and the "Text::BibTeX::File::open" method (and thus "new" as well) is just a front-end to "IO::File::open". "IO::File::open", in turn, is a front-end either to Perl's builtin "open" (if called with one argument) or "sysopen" (two or three arguments). To save you the trouble of going off and reading all those man pages, here's the trick: if you pass just a filename to "Text::BibTeX::File"'s "new" method, then it's treated just like a filename passed to Perl's builtin "open": my $append_file = new Text::BibTeX::File ">>$filename" or die "couldn't open $filename for appending: $! "; opens $filename for appending. If, later on, you have an entry from another file (say $entry), then you can append it to $append_file by just writing it as usual: $entry->write ($append_file); See "append_entries" in the examples/ subdirectory of the "Text::BibTeX" distribution for a complete example. C LIBRARY
This section covers frequently-asked questions about btparse, the C component of btOOL. Is there a Python binding for btparse yet? Not that I know of. I haven't written one. If you do so, please let me know about it. SEE ALSO
btparse, Text::BibTeX AUTHOR
Greg Ward <gward@python.net> COPYRIGHT
Copyright (c) 1997-2000 by Gregory P. Ward. All rights reserved. This file is part of the Text::BibTeX library. This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself. btparse, version 0.63 2012-05-12 btool_faq(3)
All times are GMT -4. The time now is 12:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy