Adding test to beginning and end of list in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding test to beginning and end of list in a file
# 1  
Old 02-01-2016
Adding test to beginning and end of list in a file

Hi all and apologies for the silly question, but I've searched and I can't get this right.

I have a list of email addresses in a file that I need to blacklist (spam). the list is quite long and I would need to script a small routine so that I can get the following for each line in the file:
Code:
db spamassassin setprop wbl.global bademail@mail.com Black

So basically the bademail@mail.com is the variable and the rest needs to be added to each line in the file...

Thank you in advance and best to all
gio

Last edited by Don Cragun; 02-01-2016 at 03:38 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 02-01-2016
Hello bm555,

Welcome to forums, hope you will enjoy learning/sharing knowledge here Smilie. Request you to please show us the sample input(you could leave the sensitive data but show us near to it a test data) with expected output so that we could help you in same. Also please don't forget to user code tags for commands/codes/Inputs used in your code as per forum rules.


Thanks,
R. Singh
# 3  
Old 02-01-2016
Hi and thanks for the reply..the input file is like this:
Code:
*@netzero.com
*@tijuana.mxwh.net
*@livegamesworld.com
*@iemailbox.com
steve2v@hotmail.com
helenaljufri@yahoo.com.au
aengelberg@nglbrg.com
msteeinfo@excite.com
DelayedReturn@ato.gov.au
oreartonishaybl@outlook.com

to each line I'd like to append db spam assassin setprop wbl.global at the beginning and Black at the end of each line, so that the result is:
Code:
db spamassassin setprop wbl.global oreartonishaybl@outlook.com Black

thanks again

Moderator's Comments:
Mod Comment Please use CODE tags for sample input, sample output, and sample code; not just for code.

Last edited by Don Cragun; 02-01-2016 at 03:41 AM.. Reason: Add CODE and ICODE tags; drop EMAIL tags.
# 4  
Old 02-01-2016
Hello bm555,

Thank you for showing the sample input, please put coda tags for sample Inputs(email ids in this case). Following may help you in same.
Code:
awk '{print "db spamassassin setprop wbl.global oreartonishaybl " $0 " Black"}'  Input_file

Output will be as follows.
Code:
db spamassassin setprop wbl.global oreartonishaybl *@netzero.com Black
db spamassassin setprop wbl.global oreartonishaybl *@tijuana.mxwh.net Black
db spamassassin setprop wbl.global oreartonishaybl *@livegamesworld.com Black
db spamassassin setprop wbl.global oreartonishaybl *@iemailbox.com Black
db spamassassin setprop wbl.global oreartonishaybl steve2v@hotmail.com Black
db spamassassin setprop wbl.global oreartonishaybl helenaljufri@yahoo.com.au Black
db spamassassin setprop wbl.global oreartonishaybl aengelberg@nglbrg.com Black
db spamassassin setprop wbl.global oreartonishaybl msteeinfo@excite.com Black
db spamassassin setprop wbl.global oreartonishaybl DelayedReturn@ato.gov.au Black
db spamassassin setprop wbl.global oreartonishaybl oreartonishaybl@outlook.com Black

Also on a Solaris/SunOS system, change awkto /usr/xpg4/bin/awk, /usr/xpg6/bin/awk , or nawk.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 02-01-2016
Thank you! it worked just fine...appreciate the help indeed!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add words in beginning , end after removing a word in a file

My file has the entries like below... /dev/sds /dev/sdak /dev/sdbc /dev/sdbu I want to make the file like below echo 1 > /sys/block/sds/device/rescan echo 1 > /sys/block/sdak/device/rescan echo 1 > /sys/block/sdbc/device/rescan echo 1 > /sys/block/sdbu/device/rescan (2 Replies)
Discussion started by: saravanapandi
2 Replies

2. Shell Programming and Scripting

Add new line at beginning and end of a file

Hi, I have a specific requirement to add text at the beginning and end of a plain text file. I tried to use "sed" with '1i' and '$a' flags but these required two separate "sed" commands separated with "|". I am looking for some command/option to join these two in single command parameter. ... (6 Replies)
Discussion started by: bhupinder08
6 Replies

3. Shell Programming and Scripting

How to write a new entry at the beginning of a log file instead of at the end?

Hi Ladies and Gents, Explanation of my question with an example: Let's consider the script: backup_every_hour.sh #!/bin/bash rsync -auv $dir $backup_dir >> backup_every_hour_script.log Each time this script is called there will be a new entry at the end of the file... (1 Reply)
Discussion started by: freddie50
1 Replies

4. Shell Programming and Scripting

help with sed adding line to end of file

sed '$a\ hello' books hi i am trying to use sed to append hello to the end of the file books, but for some reason i can't get it work. It keeps sayin command garbled. Anyone know what I'm doing wrong. this is in a ksh script as well. (3 Replies)
Discussion started by: bjhum33
3 Replies

5. UNIX for Dummies Questions & Answers

rename file by adding a name in beginning

about 200 files with names as 11_0.pdb 11_60.pdb 12_12.pdb 14_180.pdb are there in my library...I need to rename all of them by addinf File in front of them as: File11_0.pdb File11_60.pdb File12_12.pdb File14_180.pdb I checked many threads but it seems i get even more confused..i... (1 Reply)
Discussion started by: kanikasharma
1 Replies

6. UNIX for Dummies Questions & Answers

Adding one string at the beginning of each line in a file

Hi, I have file a.txt as below. I want to add one string root beginning of each line. Sample file a.txt aaa bbb ccc Sample output Root aaa Root bbb Root ccc Can any one help me on this? (6 Replies)
Discussion started by: siba.s.nayak
6 Replies

7. Shell Programming and Scripting

Insert two strings at the beginning and at the end of each line of a file

Hi, excuse me for my poor english. My problem is that: I have a File i want to add to each line of that file two strings: one at the beginning of the line, one at the ending. string1="abcd" string2="efgh" i want $string1 content $string2 for each line. Is that possible? (3 Replies)
Discussion started by: Linux-fueled
3 Replies

8. Shell Programming and Scripting

Adding new line at the end of file

Hi I have few files. For some files the cursor is at the end of last line. For other files, cursor is at the new line at the end. I want to bring the cursor down to next line for the files that are having cursor at the end of last line In otherwords, I want to introduce a blank line at the... (5 Replies)
Discussion started by: somesh_p
5 Replies

9. Shell Programming and Scripting

Adding a character in the beginning of every line in a .dat file

How can i add a character(#) in the beginning of every line in a .dat file (2 Replies)
Discussion started by: Cool Coder
2 Replies

10. UNIX for Dummies Questions & Answers

cat a file from end to beginning

Is there an option, for cat, head, tail, or is there any way, to display a file from last line to first? For example, my file looks like this: aaaa bbbb cccc eeee and I would like to print or display it like this: eeee cccc bbbb aaaa thanks (5 Replies)
Discussion started by: jpprial
5 Replies
Login or Register to Ask a Question