The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need to insert new text and change existing text in a file using SED iamgeethuj Shell Programming and Scripting 4 11-25-2008 03:59 AM
How to insert some constant text at beginig of each line within a text file. Muhammad Afzal Shell Programming and Scripting 4 10-30-2008 11:01 PM
insert text into column knoxo Shell Programming and Scripting 1 03-31-2008 06:01 AM
how to insert text using variable mopimp Shell Programming and Scripting 1 03-24-2006 08:32 PM
Insert Text With Sed steveramsey UNIX for Dummies Questions & Answers 5 02-09-2006 09:48 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-20-2009
bobbasystem bobbasystem is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 19
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 (permalink)  
Old 08-20-2009
Neo's Avatar
Neo Neo is offline Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,832
What editor do you use?
  #3 (permalink)  
Old 08-20-2009
bobbasystem bobbasystem is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 19
Quote:
Originally Posted by Neo View Post
What editor do you use?
I'm using gedit editor and working on bash(sh files)
Sorry for my english. My language is Spanish

---------- 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 (permalink)  
Old 08-20-2009
Leo Gutierrez Leo Gutierrez is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 13
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 (permalink)  
Old 08-22-2009
bobbasystem bobbasystem is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 19
Quote:
Originally Posted by Leo Gutierrez View Post
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!!
  #6 (permalink)  
Old 08-20-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 553
Quote:
Originally Posted by bobbasystem View Post
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..
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0