adding text from a file to the top of the file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers adding text from a file to the top of the file
# 8  
Old 04-09-2009
Wow nice - mind to explain this one please? Smilie

Oh I see, you hand over ex commands with printf. For a moment I was shocked what printf can do Smilie

Last edited by zaxxon; 04-09-2009 at 10:33 AM..
# 9  
Old 04-09-2009
Code:
printf '$\nr file2\nw! file2\nq!' | ex - file1

ex - text editor
'ex - file1' - edit file1 in silent mode ('-')
printf '....' | ex - feed the editing command to 'ex' - commands are separated by NL (\n)
'$' - go to the end of the file (file1)
'r file2' - read in file2
'w! file2' - write out the result to file2
'q!' - quite the 'ex' session.
# 10  
Old 04-09-2009
Thank you ^^
# 11  
Old 04-10-2009
Hi,

Thnx vgersh...but i am not getting the desired output....Its showing no match ....pls help on this...
# 12  
Old 04-10-2009
I confirm , cup and paste proof, that vgersh99's code is correct

and also thank him for the trick !!!

- Laurent
# 13  
Old 04-13-2009
Hi Vgersh,

Thank you very much.....I solved the problem....its because of ' when invoked in program so I replaced ' with ''. Now its working fine. Tks for ur tip and trick.....
# 14  
Old 04-13-2009
Quote:
Originally Posted by vgersh99
Code:
printf '$\nr file2\nw! file2\nq!' | ex - file1


coooool. a use for ex!!
bonus points for vger!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grabbing top line of text in a file and setting it to a variable

If I have a txt file with test.txt somelineoftext and I want to set that line of text to variable in a script: so #!/bin/bash var='' becomes #!/bin/bash var='somelineoftext' (3 Replies)
Discussion started by: digitalviking
3 Replies

2. Shell Programming and Scripting

editing line in text file adding number to value in file

I have a text file that has data like: Data "12345#22" Fred ID 12345 Age 45 Wilma Dino Data "123#22" Tarzan ID 123 Age 33 Jane I need to figure out a way of adding 1,000,000 to the specific lines (always same format) in the file, so it becomes: Data "1012345#22" Fred ID... (16 Replies)
Discussion started by: say170
16 Replies

3. Shell Programming and Scripting

Adding text into file

Hello, I after some assistance please. Below is a file I need to read and for each line write an output. My input file looks like this 2 20008 2003-08-26 2 20032 2003-08-26 2 20041 2003-08-26 2 20037 2003-08-26 2 20050 2003-08-26 6 ... (6 Replies)
Discussion started by: giles.cardew
6 Replies

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

5. Shell Programming and Scripting

adding text to a file

Hi All I am making a script in which.I have a problem i try to discribe. File1 content need to be append in file 2 but such as if content already exist then dont add. File1 IS Like this myname yourname hername hisname File2 %AddNameHere myname yourname hername hisname (3 Replies)
Discussion started by: aliahsan81
3 Replies

6. UNIX for Dummies Questions & Answers

appending text on top of another file

Dear All, I have two files One is script file in which I am writing commands to append a text in a normal file. I want to insert the text on top of the file. I dont want to use sed and awk commands nor temp file. is it possible? (3 Replies)
Discussion started by: anjali
3 Replies

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

8. UNIX for Dummies Questions & Answers

Shell scripting adding text to top of file

Hi this is quite simple i am sure but without using awk or sed i need to add text to the top of a file this is what i have got so far #!bin/bash echo "Add text to top of file" read line echo $line >> file1 This adds the text to the bottom of the file can some1 please help cheers (7 Replies)
Discussion started by: meadhere
7 Replies

9. Shell Programming and Scripting

insert text into top of file

how would you insert text into a existing file using aguments first arguments being the line of text and the second argument being file name (1 Reply)
Discussion started by: jimbob
1 Replies

10. Shell Programming and Scripting

SED- Insert text at top of file

Does anyone know how to insert text at the top and bottom of a file using sed? (12 Replies)
Discussion started by: MBGPS
12 Replies
Login or Register to Ask a Question