LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 10-28-2006, 08:16 PM   #1
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Question looking for simple scripted text-editing help


hi... i have an HTML section of text for a country drop-down menu... it looks like this (trimmed example):
Code:
<option value="AF" >AFGHANISTAN</option>
<option value="AL" >ALBANIA</option>
<option value="DZ" >ALGERIA</option>
<option value="AD" >ANDORRA</option>
<option value="AO" >ANGOLA</option>
etc... etc... etc...
i was wondering if anyone could show me a shell command to change the option value to be the complete name of the country, instead of the two-letter tag... in other words, that the end-result looks like:
Code:
<option value="AFGHANISTAN" >AFGHANISTAN</option>
<option value="ALBANIA" >ALBANIA</option>
<option value="ALGERIA" >ALGERIA</option>
<option value="ANDORRA" >ANDORRA</option>
<option value="ANGOLA" >ANGOLA</option>
etc... etc... etc...
keep in mind that some of the countries have spaces in them, like CAYMAN ISLANDS or UNITED STATES OF AMERICA, etc...

your help is greatly appreciated...

Last edited by win32sux; 10-28-2006 at 08:48 PM.
 
Old 10-29-2006, 04:33 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

sed 's%=".*" >\(.*\)</%="\1" >\1</%' infile

Sample run:
Code:
$ sed 's%=".*" >\(.*\)</%="\1" >\1</%' infile 
<option value="AFGHANISTAN" >AFGHANISTAN</option>
<option value="ALBANIA" >ALBANIA</option>
<option value="ALGERIA" >ALGERIA</option>
<option value="ANDORRA" >ANDORRA</option>
<option value="ANGOLA" >ANGOLA</option>
<option value="CAYMAN ISLANDS" >CAYMAN ISLANDS</option>
<option value="UNITED STATES OF AMERICA" >UNITED STATES OF AMERICA</option>
In case you don't understand the sed command, here's a little breakdown:

You are not bound to the / as separator. I used the % because there are forward slashes in the infile.
I also used backreferencing, the string found between \( and \) in the search part can be used in the replace part as \1.

=".*" >\(.*\)</ => search part.
="\1" >\1</%' => replace part.

An example:
If this <option value="AL" >ALBANIA</option> is your input line, the search part will 'cut out' ="AL" >ALBANIA</, ALBANIA (the \(.*\) part) can be represented as \1 in the replace part.

If anything is unclear, just ask.
 
Old 10-29-2006, 04:52 AM   #3
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Original Poster
Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
thank you so much drunna!! it worked flawlessly!!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Very simple video editing rickh Linux - Software 8 08-29-2006 12:59 PM
text editing from a script vogelbaugh Linux - General 2 09-22-2005 12:53 PM
simple image editing MuzikQuest SUSE / openSUSE 3 12-06-2004 11:23 AM
text editing machinemen Linux - Newbie 2 06-18-2004 04:38 AM
Text editing PhuckFonix Linux - Newbie 5 05-22-2004 09:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 01:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration