How to insert text after a block of text?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to insert text after a block of text?
# 1  
Old 11-18-2010
How to insert text after a block of text?

Input:
Code:
fstab is a configuration 
file that contains information 
of all the partitions 

and storage devices 
in your computer. 

The file is located under /etc, 
so the full path 
to this file is /etc/fstab.

The >>>>> characters would be replaced by some texts.
For example if i run a shell script,
Code:
./run.sh sometexts infile

Output would be:
Code:
fstab is a configuration 
file that contains information 
of all the partitions 
sometexts

and storage devices 
in your computer.

The file is located under /etc, 
so the full path 
to this file is /etc/fstab.


Last edited by cola; 11-18-2010 at 09:26 AM..
# 2  
Old 11-18-2010
Using sed to replace the >> character

Code:
#!/bin/ksh
#save file as run.ksh

sed "s/>>*/$1/g" $2 > outfile

# 3  
Old 11-18-2010
Code:
$ cat run.sh 
perl -pi -e s"/>>>>>>>>/$1/" $2

./run.sh sometexts infile

# 4  
Old 11-18-2010
something like this:

run.sh
Code:
#!/bin/bash
sed -e "s/^>>>*/$1/" $2

run as:
Code:
run.sh hellohello infile

# 5  
Old 11-18-2010
There is no >>>>> characters in input file,the >>>> means the position.
Input:
Code:
fstab is a configuration 
file that contains information 
of all the partitions 

and storage devices 
in your computer. 

The file is located under /etc, 
so the full path 
to this file is /etc/fstab.

Insert texts after first block of texts.
# 6  
Old 11-18-2010
Code:
$ cat run.sh 
perl -pi -e s"/partitions/partitions\n$1/" $2

./run.sh sometexts infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to insert text within a file?

Hi, I am trying to check for missing dates in a file and would want to insert the missing date into the file. Currently the script is as below #!/bin/ksh dates="dates" cat ${dates} | grep -v "^#" curr_month=`date '+%m` curr_day=`date '+%d` curr_year=`date '+%Y` #curr_month=02... (7 Replies)
Discussion started by: newbie_01
7 Replies

2. Shell Programming and Scripting

How do I insert text with sed ?

Hi I was wondering if anyone new of a solution to this problem? I need to copy a time stamp that is on a line of .text in a text file into multiple positions on the same line. I need to insert the time stamp on the same line between every occurance of the text ".pdf_.html" right after the... (9 Replies)
Discussion started by: Paul Walker
9 Replies

3. Shell Programming and Scripting

Insert Block of Text into a File After a Ranged Search

Hello, I've been racking my brain trying to find a good way to accomplish a task. I need to insert a block of text into a file in the format of FirewallRuleSet proxy-users { FirewallRule allow to 0.0.0.0/0 } I need to insert this block of text (which could have sed special... (2 Replies)
Discussion started by: 0xception
2 Replies

4. Shell Programming and Scripting

Again: Insert text below other text

I need help with this please: I have this text: <li><a href="login.php">Ingresar</a> and I need insert this text below: <li><a href="http://localhost/dummysila/">anything<a></li> help please! Note: all this with bash....command sed I think.... (1 Reply)
Discussion started by: bobbasystem
1 Replies

5. Shell Programming and Scripting

Insert text below other text

I need help in bash. This is the problem I have a php file that I edit, add a line under another. PHP file: <select name="RecPerPage" id="RecPerPage" onchange="this.form.submit();" class="phpmaker"> <option value="50">Select version</option> </select> I need insert "<option... (5 Replies)
Discussion started by: bobbasystem
5 Replies

6. Shell Programming and Scripting

Insert Text On file

Hi All, Can someone pls help me to insert some text on a file. my file contains something like below.. AKBULBU, BALUMIL, BATCH,BATCH BOARROB, BOTAKAT, C57896, CAKIOZE, CHECMER, CICOFRA, CISZPAW,2194485 I want output as USER_ID, LOGIN_ID (6 Replies)
Discussion started by: harshakusam
6 Replies

7. Shell Programming and Scripting

Need to insert new text and change existing text in a file using SED

Hi all, I need to insert new text and change existing text in a file. For that I used the below line in the command line and got the expected output. sed '$a\ hi... ' shell > shell1 But I face problem when using the same in script. It is throwing the error as, sed: command garbled:... (4 Replies)
Discussion started by: iamgeethuj
4 Replies

8. Shell Programming and Scripting

How to insert some constant text at beginig of each line within a text file.

Dear Folks :), I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp. I can do this in vi editor by using this command :g/^/s//BBB_ e,g I have a file named as Test.dat and it containins below text: michal... (4 Replies)
Discussion started by: Muhammad Afzal
4 Replies

9. Shell Programming and Scripting

Insert text between delimiter

Can someone help me on this? I'm creating an Insert stmt script but Oracle does not accept blanks values. How can I insert the word null between two commas? I'm guessing awk or sed. Is there a good post or site with easy to understand info on awk and sed? I'm really new to unix scripts :D ... (5 Replies)
Discussion started by: ystee
5 Replies

10. UNIX for Dummies Questions & Answers

Insert Text With Sed

Hello. Trying to insert text at line 1 and after last line of file. I have searched posts but nothing seems to work. I keep getting extra characters error or nothing gets inserted into the file. #!/bin/sh touch textfile.txt sed 'i\ Add this line before every line with WORD' textfile.txt ... (5 Replies)
Discussion started by: steveramsey
5 Replies
Login or Register to Ask a Question