adding text before and after a word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting adding text before and after a word
# 1  
Old 10-12-2011
adding text before and after a word

Hello,
I have a list:
i.e:
Code:
40331786
50331787
30331788
30331789
30331790
50331791
50331792
50331793
70331794
70331795
70331796
...
...

and I need to add text before and after each number:
i.e

Code:
before_40331786_after
before_50331787_after
before_30331788_after
before_30331789_after
before_30331790_after
before_50331791_after
before_50331792_after
before_50331793_after
before_70331794_after
before_70331795_after
before_70331796_after

Please help.

Moderator's Comments:
Mod Comment Please use code tags

Last edited by zaxxon; 10-12-2011 at 10:38 AM.. Reason: code tags, see PM
# 2  
Old 10-12-2011
Code:
$ awk '{print "before_"$0"_after"}' infile
$
$ perl -pe 's/(.*)/before_$1_after/' infile

This User Gave Thanks to jayan_jay For This Post:
# 3  
Old 10-12-2011
Thanks a lot
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Adding word in blank space

Hi, var=QSB SBD SDN SGJ SJP SKB SKD SLP SML SNB SRE SRG STP TAJ UMP UNO VKS VND VNS WAH ZRR I have to put *.sql after every word What I did echo $var>/root/file1.sql sed -i 's/ /*.sql /g' file1.sql cat file1.sql Output QSB*.sql SBD*.sql SDN*.sql SGJ*.sql SJP*.sql SKB*.sql... (9 Replies)
Discussion started by: kaushik02018
9 Replies

2. Shell Programming and Scripting

Adding Characters to a Word List

If I had a word list with a large amount of words in it, how would I (using a unix command) add, say, 123 to the end of each word? EDIT: The word list is stored in a large text file. I need a command that applies the ending to each word in the file and saves the result in a new text file. (7 Replies)
Discussion started by: evillion
7 Replies

3. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

4. Shell Programming and Scripting

Help adding a key word search to my script

Hello: I need help adding a key word search to my bash script. I have the following script. My boss whats the user to be able to add a search word e.g. unknown failures for the script to search the logs through and find the instances. I had originally done it so it grepped for unknown... (8 Replies)
Discussion started by: taekwondo
8 Replies

5. Shell Programming and Scripting

Adding a word into a file.

Dear friends, I am facing a problem with a flat file, to solve that file i need to add certain character in the file which I am not able to do because of "$" sign in the pattern. Situation is as follows. Flat file has word RMM$CART I want to reple this word by RMM$CART DFD The dollar "$"... (5 Replies)
Discussion started by: anushree.a
5 Replies

6. 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

7. Shell Programming and Scripting

sed for adding word

hello i have a file (myfile) contains line as follows /home/mytarget/myproject i want to add a pattern at the end of this line. my pattern is- /.*mk i want like it - /home/mytarget/myproject/*.mk i tried sed like sed 's/$//*.mk/' myfile > newfilename, but not wrking. pls... (2 Replies)
Discussion started by: shailesh_arya
2 Replies

8. Shell Programming and Scripting

Adding a word in front of a word of each line.

Adding a word in front of a word of each line.In that line only one word will be there. pl help:( (4 Replies)
Discussion started by: Ramesh Vellanki
4 Replies

9. Shell Programming and Scripting

adding text to the end of lines containing a word

I'm new to shell scripting, and need to add a series of commands to the ends of certain lines of text that contain a keyword. Any easy way to do this? Thanks (2 Replies)
Discussion started by: ironwall
2 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question