LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-11-2004, 12:03 AM   #1
wswartz
Member
 
Registered: Nov 2003
Posts: 56

Rep: Reputation: 15
Help with a script (question on strings)


I'm looking for someone to help me figure out how to accomplish a task with a shell script. I have the string variable TEXT containing the following:

TEXT=<TR><TD><INPUT TYPE=text NAME=Hour , SIZE="2" MAXLENGTH="2" VALUE="12"></TD>

(the line is an extract from a web page). Notice the part of the string that says VALUE="12"? I want to set another variable to the number in quotes. In other words, I'd like to figure out a way to extract the number after VALUE and set this number to a variable called HOUR. In this case, HOUR would equal 12.

Any ideas?
BS
 
Old 07-11-2004, 12:54 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Seems like you should be able to call sed to do it for you. If you're not familiar with sed, it a command-line text editor which allows you to edit text unseen, if you know the pattern to search for, and how to phrase the replacement text.
 
Old 07-11-2004, 01:11 AM   #3
Jerre Cope
Member
 
Registered: Oct 2003
Location: Texas (central)
Distribution: ubuntu,Slackware,knoppix
Posts: 323

Rep: Reputation: 37
example

TEXT="<TR><TD><INPUT TYPE=text NAME=Hour , SIZE=\"2\" MAXLENGTH=\"2\" VALUE=\"12\"></TD>"
echo "TEXT $TEXT"
HOUR=`echo $TEXT | sed '1,$s/.*VALUE=\"//' | sed '1,$s/\">.*$//'`
echo "HOURS $HOUR"
 
Old 07-11-2004, 08:53 AM   #4
wswartz
Member
 
Registered: Nov 2003
Posts: 56

Original Poster
Rep: Reputation: 15
Thank you very much. That worked perfectly!

BSS
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script help (arrays and strings from files) nkoplm Programming 14 12-02-2005 09:50 AM
how to find duplicate strings in vertical column of strings markhod Programming 7 11-02-2005 04:04 AM
script to exclude strings... NiallC Programming 10 03-28-2005 06:46 PM
strings question sibtay Programming 7 10-01-2004 10:37 AM
Formatted Strings in Script File mhjones Programming 1 06-07-2004 10:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:39 AM.

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