Sponsored Content
Top Forums Shell Programming and Scripting replace block of text with content of another file Post 302425796 by ripat on Sunday 30th of May 2010 10:02:31 AM
Old 05-30-2010
Nice! Thank you.

---------- Post updated at 04:02 PM ---------- Previous update was at 02:51 PM ----------

The following also works :

Code:
awk 'NR==FNR{a[NR]=$0;next}/start/{f=1;print;for (i in a) print a[i]}/end/{f=0}!f' file2 file1

I benchmarked the two methods and the "getline / redirection" thing seems to be much faster on large files. Something like 5 times faster on a large file2 file (18.000 lines)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SED to replace file content

Hi, I want to replace _F* by _F in a xml file. what is the sed command. I have tried sed "s/_F$/_F/g" or sed "s/_F*/_F/g" , but it does not work. thx file content <TAG>KC_FOU</TAG> <TAG>KC_FABC</TAG> <TAG>KC_FABCDG</TAG> desire output <TAG>KC_F</TAG> <TAG>KC_F</TAG> <TAG>KC_F</TAG> (6 Replies)
Discussion started by: godfreyyip
6 Replies

2. Shell Programming and Scripting

Replace text block in multiple files

I need to replace (delete) a text block in a bunch of files, its a html table, almost at the end of pages but the location varies. In Windows I used Filemonkey, but nothing like that in Unix? There is replace from mysql, but how does it deal with newlines? sed only works with single lines,... (6 Replies)
Discussion started by: eiland
6 Replies

3. Shell Programming and Scripting

Replace file content after checking value

Our system is receiving one feed from the third party. One of the field in the flat file is ID which id from position 19 to 27. In some cases this ID is coming as 9 zeros (000000000) or 1 right padded zero. ( 0) For these specific records I want to replace fthis field with blank... (3 Replies)
Discussion started by: varunrbs
3 Replies

4. Shell Programming and Scripting

using sed/awk to replace a block of text in a file?

My apologies if this has been answered in a previous post. I've been doing a lot of searching, but I haven't been able to find what I was looking for. Specifically, I am wondering if I can utilize sed and/or awk to locate two strings in a file, and replace everything between those two strings... (12 Replies)
Discussion started by: kiddsupreme
12 Replies

5. Shell Programming and Scripting

Need to replace particular content in a xml file

Hi, My requirement is to find a text and replace it with another in a XML file. I am new to Unix,Please provide some suggestion to achieve. Find: <Style ss:ID="ColumnHeader1"> Replace with: <Style ss:ID="ColumnHeader1"> <Borders> <Border ss:Position="Bottom"... (4 Replies)
Discussion started by: cnraja
4 Replies

6. Shell Programming and Scripting

Script to create a text file whose content is the text of another files

Hello everyone, I work under Ubuntu 11.10 (c-shell) I need a script to create a new text file whose content is the text of another text files that are in the directory $DIRMAIL at this moment. I will show you an example: - On the one hand, there is a directory $DIRMAIL where there are... (1 Reply)
Discussion started by: tenteyu
1 Replies

7. Shell Programming and Scripting

Replace the content of file with incremented value

I have a file myfile with only one value 1000.I am using it in a shell script.Each time i run the script,the file shud get incremented by 1. I have used the below code for incrementing the value- curr=`cat myfile` echo $curr curr=`expr $curr + 1` But i am not sure how to save this replaced... (2 Replies)
Discussion started by: saga20
2 Replies

8. Shell Programming and Scripting

Bash shell: Replace a text block by another

Hello, I'm an starter in Bash scripting. I would like to write a script in Bash shell that replaces a specific text block (a function) by another text block in a file: for example in my file --> $HOME/myFile.js replacing following function between other functions in the file: function ABC()... (6 Replies)
Discussion started by: om1559
6 Replies

9. Shell Programming and Scripting

Sed: replace content from file with the content from file

Hi, I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C. Thanks a lot!! Here is a sample of my question. e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 Replies

10. Shell Programming and Scripting

Replace file name with Space as content

Hi, I am having a files in my directory like this: 2014 1049_file1.txt 2014 1050_file2.txt 2014 1110_file3.txt 2014 1145_file4.txt 2014 2049_file5.txt I need to replace the above file names like this without changing the content of filename: file1.txt file2.txt file3.txt... (10 Replies)
Discussion started by: rohit_shinez
10 Replies
SAFE_FINGER(8)						     Linux Programmer's Manual						    SAFE_FINGER(8)

NAME
safe_finger - finger client wrapper that protects against nasty stuff from finger servers SYNOPSIS
safe_finger [finger_options] DESCRIPTION
The safe_finger command protects against nasty stuff from finger servers. Use this program for automatic reverse finger probes from the tcp_wrapper (tcpd) , not the raw finger command. The safe_finger command makes sure that the finger client is not run with root privileges. It also runs the finger client with a defined PATH environment. safe_finger will also protect you from problems caused by the output of some finger servers. The problem: some programs may react to stuff in the first column. Other programs may get upset by thrash anywhere on a line. File systems may fill up as the finger server keeps sending data. Text editors may bomb out on extremely long lines. The finger server may take forever because it is somehow wedged. safe_finger takes care of all this badness. SEE ALSO
hosts_access(5), hosts_options(5), tcpd(8) AUTHOR
Wietse Venema, Eindhoven University of Technology, The Netherlands. Linux 21th June 1997 SAFE_FINGER(8)
All times are GMT -4. The time now is 08:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy