Command line: add text wrapper around words


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command line: add text wrapper around words
# 1  
Old 10-17-2012
Command line: add text wrapper around words

I am trying to build a sinkhole for BIND. I created a master zone file for malicious domains and created a separate conf file, but I am stuck.

I have a list of known bd domains that is updated nightly. The file simply contains the list of domains, one on each line:

Bad.com
Bad2.com
Bad3.com
...
EOF

I need to add a zone wrapper around each domain, so they look like this:
zone "bad.com" IN { type master; file "/var/named/bad/malware.zone";};
zone "bad2.com" IN { type master; file "/var/named/bad/malware.zone";};
zone "bad3.com" IN { type master; file "/var/named/bad/malware.zone";};

I thought I could use sed to do this, but I can't figure out how to insert in the middle of a line only at the beggining or end.

Any help would be greatly appreciated.
# 2  
Old 10-17-2012
We are not clear little bit.
per my understanding..
Code:
awk '{print "zone "$0 "IN { type master; file /var/named/bad/malware.zone}"}' test.txt

This User Gave Thanks to bmk For This Post:
# 3  
Old 10-17-2012
Code:
sed 's/^/zone "/;s:$:" IN { type master; file "/var/named/bad/malware.zone";};:' file

This User Gave Thanks to elixir_sinari For This Post:
# 4  
Old 10-17-2012
I love both answers, thank you! The only problem with using the awk command above is that it does not retain the quotation marks when you pipe it to a file. I added a couple of escapes and it worked great!

Again, I appreciate the help.
# 5  
Old 10-17-2012
a ksh:
Code:
while read d;do echo 'zone "'${d}'" IN { type master; file "/var/named/bad/malware.zone";};';done<infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

2. Shell Programming and Scripting

How to add line breaks to perl command with large text in single quotes?

Below code extracts multiple field values from XML into array and prints all in one line. perl -nle '@r=/(?: jndiName| authDataAlias| value| minConnections| maxConnections| connectionTimeout| name)="(+)/g and print join ",",$ENV{tIPnSCOPE},$ENV{pr ovider},$ENV{impClassName},@r' server.xml ... (4 Replies)
Discussion started by: kchinnam
4 Replies

3. Shell Programming and Scripting

wrapper script design for gnu ed text editor i/o

Hi. I'm having trouble writing a wrapper script for the command line text editor gnu ed. I want to be able to run the following algorithm on ed: 1. Display, on stdout, a command which I intend to feed into ed (before I actually feed it to ed). 2. Actually feed the command into ed's stdin.... (2 Replies)
Discussion started by: vomv1988
2 Replies

4. UNIX for Dummies Questions & Answers

extract text between two words on a single line

Hi Guys, Can someone help me with a way to extract text between two words on a single line. For example if the file has below content I want to extract all text between b and f inclusive of b and f. Aparently sed does this but does it line by line and I guess it cannot read word by word. ... (11 Replies)
Discussion started by: krishnaux
11 Replies

5. Shell Programming and Scripting

How to set mutliple words variable from command line

I'm writing a script (C shell) to search for a pattern in file. For example scriptname pattern file1 file2 filenN I use for loop to loop through arguments argv, and it does the job if all arguments are supplied. However if only one argument is supplied (in that case pattern ) it should ask to... (5 Replies)
Discussion started by: patryk44
5 Replies

6. Shell Programming and Scripting

deleting blank line and row containing certain words in single sed command

Hi Is it possible to do the following in a single command /usr/xpg4/bin/sed -e '/rows selected/d' /aemu/CALLAUTO/callauto.txt > /aemu/CALLAUTO/callautonew.txt /usr/xpg4/bin/sed -e '/^$/d' /aemu/CALLAUTO/callautonew.txt > /aemu/CALLAUTO/callauto_new.txt exit (1 Reply)
Discussion started by: aemunathan
1 Replies

7. Shell Programming and Scripting

alias two words command line

Hello, i would like to alias aptitude install for sudo aptitude install, is it possible, and how ? i read the man alias page, but i think i have to use something with \ or { but i don't know exactly what. (3 Replies)
Discussion started by: harlock59
3 Replies

8. UNIX for Dummies Questions & Answers

how to extend words on a command line ?

within a unix window, how do you setup your session to extend a word, by hitting the "esc" key twice. e.g. ls -la scri (esc key, esc key) thankyou (6 Replies)
Discussion started by: venhart
6 Replies

9. UNIX for Dummies Questions & Answers

overlapping words on command line

i tried resize command , but it's not working...... (4 Replies)
Discussion started by: gaurav123
4 Replies

10. UNIX for Dummies Questions & Answers

Identify duplicate words in a line using command

Hi, Let me explain the problem clearly: Let the entries in my file be: lion,tiger,bear apple,mango,orange,apple,grape unix,windows,solaris,windows,linux red,blue,green,yellow orange,maroon,pink,violet,orange,pink Can we detect the lines in which one of the words(separated by field... (8 Replies)
Discussion started by: srinivasan_85
8 Replies
Login or Register to Ask a Question