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
ACCESS(5)							File Formats Manual							 ACCESS(5)

NAME
access - format of Postfix access table SYNOPSIS
postmap /etc/postfix/access DESCRIPTION
The optional access table directs the Postfix SMTP server to selectively reject or accept mail. Access can be allowed or denied for spe- cific host names, domain names, networks, host network addresses or mail addresses. Normally, the access table is specified as a text file that serves as input to the postmap(1) command. The result, an indexed file in dbm or db format, is used for fast searching by the mail system. Execute the command postmap /etc/postfix/access in order to rebuild the indexed file after changing the access table. When the table is provided via other means such as NIS, LDAP or SQL, the same lookups are done as for ordinary indexed files. Alternatively, the table can be provided as a regular-expression map where patterns are given as regular expressions. In that case, the lookups are done in a slightly different way as described below. TABLE FORMAT
The format of the access table is as follows: pattern action When pattern matches a mail address, domain or host address, perform the corresponding action. blank lines and comments Empty lines and whitespace-only lines are ignored, as are lines whose first non-whitespace character is a `#'. multi-line text A logical line starts with non-whitespace text. A line that starts with whitespace continues a logical line. EMAIL ADDRESS PATTERNS
With lookups from indexed files such as DB or DBM, or from networked tables such as NIS, LDAP or SQL, the following lookup patterns are examined in the order as listed: user@domain Matches the specified mail address. domain.tld Matches domain.tld as the domain part of an email address. The pattern domain.tld also matches subdomains, but only when the string smtpd_access_maps is listed in the Postfix par- ent_domain_matches_subdomains configuration setting. Otherwise, specify .domain.tld (note the initial dot) in order to match subdo- mains. user@ Matches all mail addresses with the specified user part. Note: lookup of the null sender address is not possible with some types of lookup table. By default, Postfix uses <> as the lookup key for such addresses. The value is specified with the workaround is to specify smtpd_null_access_lookup_key parameter in the Postfix main.cf file. ADDRESS EXTENSION
When a mail address localpart contains the optional recipient delimiter (e.g., user+foo@domain), the lookup order becomes: user+foo@domain, user@domain, domain, user+foo@, and user@. HOST NAME
/ADDRESS PATTERNS With lookups from indexed files such as DB or DBM, or from networked tables such as NIS, LDAP or SQL, the following lookup patterns are examined in the order as listed: domain.tld Matches domain.tld. The pattern domain.tld also matches subdomains, but only when the string smtpd_access_maps is listed in the Postfix par- ent_domain_matches_subdomains configuration setting. Otherwise, specify .domain.tld (note the initial dot) in order to match subdo- mains. net.work.addr.ess net.work.addr net.work net Matches any host address in the specified network. A network address is a sequence of one or more octets separated by ".". ACTIONS
[45]NN text Reject the address etc. that matches the pattern, and respond with the numerical code and text. REJECT Reject the address etc. that matches the pattern. A generic error response message is generated. OK Accept the address etc. that matches the pattern. all-numerical An all-numerical result is treated as OK. This format is generated by address-based relay authorization schemes. restriction... Apply the named UCE restriction(s) (permit, reject, reject_unauth_destination, and so on). REGULAR EXPRESSION TABLES
This section describes how the table lookups change when the table is given in the form of regular expressions. For a description of regu- lar expression lookup table syntax, see regexp_table(5) or pcre_table(5). Each pattern is a regular expression that is applied to the entire string being looked up. Depending on the application, that string is an entire client hostname, an entire client IP address, or an entire mail address. Thus, no parent domain or parent network search is done, user@domain mail addresses are not broken up into their user@ and domain constituent parts, nor is user+foo broken up into user and foo. Patterns are applied in the order as specified in the table, until a pattern is found that matches the search string. Actions are the same as with indexed file lookups, with the additional feature that parenthesized substrings from the pattern can be inter- polated as $1, $2 and so on. BUGS
The table format does not understand quoting conventions. SEE ALSO
postmap(1) create mapping table smtpd(8) smtp server pcre_table(5) format of PCRE tables regexp_table(5) format of POSIX regular expression tables LICENSE
The Secure Mailer license must be distributed with this software. AUTHOR(S) Wietse Venema IBM T.J. Watson Research P.O. Box 704 Yorktown Heights, NY 10598, USA ACCESS(5)
All times are GMT -4. The time now is 08:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy