LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-25-2004, 02:35 PM   #1
Joey^s
LQ Newbie
 
Registered: Nov 2004
Posts: 6

Rep: Reputation: 0
Script questions


I hope you can help me here with my 2 questions on bash scripts

How do I check if entered strings are valid emails or urls?

How would I search and display the variables, of a string that contains variables seperated by ^?

For example, how would I search all the strings with a variable 1 in this file, and then display each number as a seperate variable
2^1^4^5^7
3^7^^4^9^0
3^1^2^7

I know i have to use sed, but I havnt been able to get it right

Last edited by Joey^s; 11-25-2004 at 05:18 PM.
 
Old 11-25-2004, 05:23 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Re: Script questions

Hi, and welcome to LQ!

Quote:
Originally posted by Joey^s
How do I check if entered strings are valid emails or urls?
Read the relevant RFCs to determine what
comprises a valid e-mail address or URL, and
then use an appropriate regular expression :)

Something like
egrep -e "[a-zA-Z]+([[:alnum:]]|[.-])*@[a-zA-Z]+([[:alnum:]]|[.-])\.[a-zA-Z]+[[:alnum:]]*"
MAY do the trick, I didn't even bother trying to test
it, but you get the idea...

Quote:
How would I search and display the variables, of a string that contains variables seperated by ^?

For example, how would I search all the strings with a variable 1 in this file, and then display each number as a seperate variable
2^1^4^5^7
3^7^^4^9^0
3^1^2^7
Sorry, I can't understand what you're trying to
achieve at all ...


Cheers,
Tink
 
Old 11-25-2004, 06:12 PM   #3
Joey^s
LQ Newbie
 
Registered: Nov 2004
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks a lot Tinkster for the valid check script


Sorry for not describing my second question right, I'll try again.

I have a file containing lines of text. Each line is a string. Like this:

^Eminem^Kim^Without Me
^johnny cash^san quentin^A Boy Named Sue
^Beatles^ Hard Days Night^Imagine^Strawberry Fields

So the first string is "^Eminem^Kim^Without Me"

What I want to do is now, split that string into the variables "Eminem" "Kim" and "Without Me", assigning them variable names like author, song1, song2

I also wasnt to be able to search the file for authors and song names

I know I have to use sed, but I havnt been able to get it right
 
Old 11-25-2004, 06:17 PM   #4
krock923
Member
 
Registered: Jul 2004
Posts: 171

Rep: Reputation: 30
maybe using cut and ^ as the delimeter?
 
Old 11-29-2004, 02:53 AM   #5
Joey^s
LQ Newbie
 
Registered: Nov 2004
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks for help krock923

When I use:

cut -d^ -f1 myalbums

I recieve:

Eminem
johnny cash
Beatles


So, how would I assign the "Eminem" to the variable author1, and "Kim" to song1?
 
  


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
Script questions tgreiner Linux - Newbie 6 04-05-2005 01:00 AM
script questions shaoshuai97 Linux - Certification 2 10-12-2004 10:00 AM
two shell script questions tutwabee Linux - General 4 08-10-2004 06:03 PM
Some questions about a rc.firewall script matruschka Linux - Security 3 08-01-2004 08:47 AM
Shell Script Questions Col Panic Linux - General 13 10-12-2003 12:51 PM

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

All times are GMT -5. The time now is 11:56 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