Sponsored Content
Top Forums Shell Programming and Scripting [bash help]Adding multiple lines of text into a specific spot into a text file Post 302401413 by karthigayan on Saturday 6th of March 2010 02:11:21 AM
Old 03-06-2010
You can have the text to be insert in a file.Here I had the main file as "file1" and had the text in the file "file2".

file1:
Code:
  
                IN      NS      ns1.domain.tld.
                IN      NS      ns2.domain.tld.
                IN      NS      ns3.domain.tld.
                IN      NS      ns4.domain.tld.

                IN    A    255.255.255.255

file2:
Code:
                 IN      MX      mx1.domain.tld.
                 IN      MX      mx2.domain.tld.
                 IN      MX      mx3.domain.tld.
                 IN      MX      mx4.domain.tld.


Code:
str=""
while read line
do
        str="$str$line\n"
done < "file2"

while read line
do
        match=`sed -r "s/(^ *IN +A.+$)/$str\n\1\n/g" <<<"$line"`
        echo -e "$match" >>resultfile
done < "file1"

Here the result will store on the file resultfile
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

adding text to a file between lines

Suppose content of my first file: first line second line third line How can i insert text between "first line" & "second Iline" Any help?????/ (7 Replies)
Discussion started by: bishweshwar
7 Replies

2. Shell Programming and Scripting

Adding specific text and spaces to each line in a text file

Hi, I wanted to add specific text to each row in a text file containing three rows. Example: 0 8 7 6 5 5 7 8 9 0 7 9 7 8 9 0 1 2 And I want to add a 21 at the beginning of the first row, and blank spaces at the beginning of the second two rows. To get this: 21 0 8 7 6 5 5 7 8... (4 Replies)
Discussion started by: hertingm
4 Replies

3. Shell Programming and Scripting

Adding text to file on certain lines with(special characters)

I need to add "new lines" of text with special characters, to specific lines in the file. There are 3 modifications needed. Been testing 2 here without success. #!/usr/bin/perl use FileHandle; $file=FileHandle->new; $FILENAME="/opt/etc/usr/file.txt"; $file->open ("<$FILENAME") or die... (13 Replies)
Discussion started by: A4ron4perl
13 Replies

4. Shell Programming and Scripting

how to Insert values in multiple lines(records) within a pipe delimited text file in specific cols

this is Korn shell unix. The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Discussion started by: vasan2815
4 Replies

5. UNIX for Dummies Questions & Answers

Adding tags to a specific column of a space delimited text file

I have a space delimited text file with two columns. I would like to add NA to the first column of the text file. Input: 19625 10.4791768259 19700 10.8146489183 19701 10.9084026759 19702 10.9861346978 19703 10.9304364984 Output: NA19625 10.4791768259 NA19700 10.8146489183... (1 Reply)
Discussion started by: evelibertine
1 Replies

6. UNIX for Dummies Questions & Answers

How to grep multiple lines from a text file using another text file?

I would like to use grep to select multiple lines from a text file using a single-column text file. Basically I want to only select lines from the first text file where the second column of the first text file matches the second text file. How do I go about doing that? Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

7. Shell Programming and Scripting

Adding text to the end of the specific line in a file(only to the first occurrence of it)

Hi, I want to add a text to the end of the specific line in a file. Now my file looks like this: 999 111 222 333 111 444 I want to add the string " 555" to the end of the first line contaning 111. Moreover, I want to insert a newline after this line containg the "000" string. The... (8 Replies)
Discussion started by: wenclu
8 Replies

8. UNIX for Dummies Questions & Answers

About adding users from a text file using bash

hello, I try to add users from a text file with this form: username:groupename:homedir first i extract data which is separated by ":" then i use useradd to add users/groups. but,,, my code doesn't works : #!/bin/bash echo "give me a text file: " read dir # control if... (2 Replies)
Discussion started by: ref012
2 Replies

9. Shell Programming and Scripting

Printing multiple lines on the same line between specific text

This is an extract from a large file. The lines that start with fc are ports on a fabric switch. In between each fc port there is information about the port. fc2/12 is up Port description is SEIEDISCOVER-3 Speed is 4 Gbps fc2/13 is down (Administratively down) fc2/14 is up Port... (1 Reply)
Discussion started by: kieranfoley
1 Replies

10. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies
FONTIMAGE(1)						      General Commands Manual						      FONTIMAGE(1)

NAME
fontimage - produce a font thumbnail image SYNOPSIS
fontimage [--help] [--width num] [--height num] [--pixelsize num] [--text string] [--o outputfile] [--usage] [--version] fontfile DESCRIPTION
The program fontimage loads a font, which may be in any format fontforge(1) can read, and then produces an image showing representative glyphs of the font. OPTIONS
--help Provide a description with a list of the available options. --width num Specifies the width of the output image. If this is omitted the image will be as wide as necessary to display the text. --height num Specifies the height of the output image. If this is omitted the image will be as high as necessary to display the text. --pixelsize num Specifies the pixelsize used to display the text. This argument may be specified multiple times and each refers to any --text lines that follow it. --text string Specifies a line of text to be displayed. The string must be in UTF-8. This argument may be specified multiple times to provide several lines of text. If no --text arguments are supplied fontimage will examine the font, looking for various scripts it knows about, and will try to display something appropriate for each. -o outfile Specifies the output filename for the image. The type of image will be determined by the file's extension. Currently only ".bmp" and ".png" are recognized. If omitted fontimage will choose an output name based on the font's fontname field. --usage Display the usage description. --version Display the current version SEE ALSO
fontforge(1) The HTML version of the fontforge manual at: http://fontforge.sourceforge.net/ AUTHOR
Copyright (C) 2006 by George Williams (gww@silcom.com). 26 October 2006 FONTIMAGE(1)
All times are GMT -4. The time now is 04:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy