LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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
 
LinkBack Search this Thread
Old 10-28-2006, 08:16 PM   #1
win32sux
Moderator
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
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
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 7,514
Blog Entries: 1

Rep: Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139
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
Moderator
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are 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/Novell 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


All times are GMT -5. The time now is 05:27 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration