Adding words to beginning of lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding words to beginning of lines
# 1  
Old 04-03-2008
Adding words to beginning of lines

I have a file that contains a great number of lines, let's say 183 lines, and I want to add: echo " to the beginning of each line. What is the easiest way to do it?

Tx
# 2  
Old 04-03-2008
I would use sed for that purpose, remember to escape the "
# 3  
Old 04-03-2008
Code:
 awk '{print "echo \""$0}' infile

or

Code:
 sed 's/^/echo "/' infile

# 4  
Old 04-03-2008
Quote:
Originally Posted by Ernst
I have a file that contains a great number of lines, let's say 183 lines, and I want to add: echo " to the beginning of each line. What is the easiest way to do it?

Tx

Code:
cat filename.txt  | perl -ne 'print "echo " . $_' > output.txt

# 5  
Old 04-03-2008
Another one:

Code:
sed 's/.*/echo "&"/' file

Regards
# 6  
Old 04-03-2008
Thanks!

This command works: sed 's/.*/echo "&"/'

What if I want at the same time to add something to the end of each line.
i.e echo "unixtest=test" >> firsttest

what would the command be to add the >> firsttest to teh end of each line
# 7  
Old 04-03-2008
Code:
sed 's/.*$/& >> firsttest/' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

View a file and count all words beginning with specificletter

I am trying to write a command and need to count all the words within the file which begin with the letter S I have run this command $ grep '^' TheAgileApproach.dat | wc -l 0 $ grep '^' TheAgileApproach.dat | wc -l 1 When I remove the wc -l I see the output as below: $ grep '^'... (7 Replies)
Discussion started by: simpsa27
7 Replies

2. Shell Programming and Scripting

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: db... (4 Replies)
Discussion started by: bm555
4 Replies

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

4. Shell Programming and Scripting

Adding a text in the beginning of a line

Hi, I am doing something like below: cat file1>file3and cat file2>>file3 I wanted to check if there is a way to write a custom message(hardcoded message)something like below at the beginning of each line then PIPE delimitiation and then followed by remaining record. cat file1... (7 Replies)
Discussion started by: Saanvi1
7 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 words after a set of words

Greetings. I am a UNIX newbies. I am currently facing difficulties dealing with a large data set and I would like to ask for helps. I have a input file like this: ak 1 AAM1 ak 2 AAM1 ak 3 AAM1 ak 11 AMM2 ak 12 AMM2 ak 13 AMM2 ak 14 AMM2 Is there any possibility for me to... (7 Replies)
Discussion started by: Amanda Low
7 Replies

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

8. UNIX for Dummies Questions & Answers

Remove words beginning with a certain character from a file

Hi, how could you go about removing words that begin with a certain character. assuming that this character is '-' I currently have echo "-hello" | sed s/-/""/ which replaces the leading dash with nothing but I want to remove the whole word, even if there are multiple words beginning... (3 Replies)
Discussion started by: skinnygav
3 Replies

9. Shell Programming and Scripting

Swapping lines beginning with certain words using sed/awk

I have a large file which reads like this: fixed-address 192.168.6.6 { hardware ethernet 00:22:64:5b:db:b1; host X; } fixed-address 192.168.6.7 { hardware ethernet 00:22:64:5b:db:b3; host Y; } fixed-address 192.168.6.8 { hardware ethernet 00:22:64:5b:db:b4; host A; }... (4 Replies)
Discussion started by: ksk
4 Replies

10. 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
Login or Register to Ask a Question