Insert text below other text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert text below other text
# 1  
Old 08-20-2009
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 value="anything">Select version1</option>" below
"<option value="50">Select version</option>"

Please help me...

I tried for a long time but not get anything
# 2  
Old 08-20-2009
What editor do you use?
# 3  
Old 08-20-2009
Quote:
Originally Posted by Neo
What editor do you use?
I'm using gedit editor and working on bash(sh files)
Sorry for my english. My language is Spanish Smilie

---------- Post updated at 08:15 PM ---------- Previous update was at 08:02 PM ----------

I tried this:

sed '/^<option value="50">Seleccione una version...</option>/<option value="50">Select version</option>'
file > newfile

but the bash interpret leaves no place < or > or / in the text to insert.
I think it is confused with bash syntaxis.
# 4  
Old 08-20-2009
Suponiendo que "file.txt" tiene el siguiente contenido:
Code:
leo@lein:~/Escritorio$ cat "file.txt"
<select name="RecPerPage" id="RecPerPage" onchange="this.form.submit();" class="phpmaker">
<option value="50">Select version</option>
</select>
leo@lein:~/Escritorio$

Y tengo un script "shell.sh" con el siguiente contenido:
Code:
#!/usr/bin/bash
cat file.txt | sed '/option value/ a\
<option value="anything">Select version1</option>'

Ahora ejecutandolo:
Code:
leo@lein:~/Escritorio$ bash shell.sh
<select name="RecPerPage" id="RecPerPage" onchange="this.form.submit();" class="phpmaker">
<option value="50">Select version</option>
<option value="anything">Select version1</option>
</select>
leo@lein:~/Escritorio$

Solo redirigelo:
Code:
leo@lein:~/Escritorio$ bash shell.sh > nuevo.txt
leo@lein:~/Escritorio$ cat nuevo.txt 
<select name="RecPerPage" id="RecPerPage" onchange="this.form.submit();" class="phpmaker">
<option value="50">Select version</option>
<option value="anything">Select version1</option>
</select>
leo@lein:~/Escritorio$

Saludos.
O solo:
Code:
sed '/option value/ a\<option value="anything">Select version1</option>' "file.txt"

# 5  
Old 08-20-2009
Quote:
Originally Posted by bobbasystem
I'm using gedit editor and working on bash(sh files)
...
Isn't gedit a graphical editor ?
Editing files in it should be pretty intuitive.

Or are you trying to modify the files from the command line ?

tyler_durden

Guess you are indeed:

Code:
$ 
$ cat data.txt
<select name="RecPerPage" id="RecPerPage" onchange="this.form.submit();" class="phpmaker">
<option value="50">Select version</option>
</select>
$ 
$ sed 's/\(<option.*>\)/\1\n<option value="anything">Select version1<\/option>/' data.txt
<select name="RecPerPage" id="RecPerPage" onchange="this.form.submit();" class="phpmaker">
<option value="50">Select version</option>
<option value="anything">Select version1</option>
</select>
$


Last edited by durden_tyler; 08-20-2009 at 09:23 PM..
# 6  
Old 08-22-2009
Quote:
Originally Posted by Leo Gutierrez
Suponiendo que "file.txt" tiene el siguiente contenido:
Code:
leo@lein:~/Escritorio$ cat "file.txt"
<select name="RecPerPage" id="RecPerPage" onchange="this.form.submit();" class="phpmaker">
<option value="50">Select version</option>
</select>
leo@lein:~/Escritorio$

Y tengo un script "shell.sh" con el siguiente contenido:
Code:
#!/usr/bin/bash
cat file.txt | sed '/option value/ a\
<option value="anything">Select version1</option>'

Ahora ejecutandolo:
Code:
leo@lein:~/Escritorio$ bash shell.sh
<select name="RecPerPage" id="RecPerPage" onchange="this.form.submit();" class="phpmaker">
<option value="50">Select version</option>
<option value="anything">Select version1</option>
</select>
leo@lein:~/Escritorio$

Solo redirigelo:
Code:
leo@lein:~/Escritorio$ bash shell.sh > nuevo.txt
leo@lein:~/Escritorio$ cat nuevo.txt 
<select name="RecPerPage" id="RecPerPage" onchange="this.form.submit();" class="phpmaker">
<option value="50">Select version</option>
<option value="anything">Select version1</option>
</select>
leo@lein:~/Escritorio$

Saludos.
O solo:
Code:
sed '/option value/ a\<option value="anything">Select version1</option>' "file.txt"

Thanks Leo!! Smilie
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

Insert text before first 'n' lines

I want to put a particular text, say, the hash '#' before each of the first n lines of a file. How can I do that? (4 Replies)
Discussion started by: hbar
4 Replies

3. Shell Programming and Scripting

Insert value to db from text file

Hi, I have a single value in insertval file. I want to load that value to database with the current date. I tried the below code but it is inserting <NULL> to database and echo $c is also null. cat insertval | awk -F ' ' '{print $1}' > c echo c=$c data=`sqlplus -s user/pwd@hostname <<EOF ... (5 Replies)
Discussion started by: Neethu
5 Replies

4. Shell Programming and Scripting

Insert text using sed

sed 's/$/TEST/g' will insert TEST at the end of each line. i want to insert TEST at column 64 (7 Replies)
Discussion started by: lawsongeek
7 Replies

5. Shell Programming and Scripting

How to insert text after a block of text?

Input: 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... (5 Replies)
Discussion started by: cola
5 Replies

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

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

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

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

10. Shell Programming and Scripting

insert text into column

Hello! I have a text file containing some text : : : bla other text : : : bla any text : : : bla containing 3 columns separated by the ':' sign. Now i want to insert 'this' in the 2nd line after the 2nd column-deliminiter (i.e. into 3rd column), like some text : : : bla other text :... (1 Reply)
Discussion started by: knoxo
1 Replies
Login or Register to Ask a Question