LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-15-2014, 12:01 AM   #1
sryzdn
Member
 
Registered: Feb 2013
Posts: 274

Rep: Reputation: 9
shell scripting - validation of a list


Hello

I have the follwoing command:

Quote:
[me@localhost ~]$ for i in {1..10}; do echo "(${RANDOM:0:3}) ${RANDOM:0:3}-${RANDOM:0:4)" >> numlist.txt; done
But it does not work. I cannot figure out where I am going wrong. Could anyone please give me a hint on it?
 
Old 06-15-2014, 02:59 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by sryzdn View Post
Could anyone please give me a hint on it?
Learn where to use parentheses and where not?
 
Old 06-16-2014, 08:26 AM   #3
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
Are you going to generate phone numbers?
As unSpawn said, using parentheses at correct place is important.

I am little curious about your third random variable which is of four digit. You have started it with curly braces and ended with parentheses (round bracket). Does it not give you any error?

Do you want to generate 10 numbers like this?
Quote:
(250) 116-1101
 
Old 06-16-2014, 09:37 AM   #4
sryzdn
Member
 
Registered: Feb 2013
Posts: 274

Original Poster
Rep: Reputation: 9
Quote:
Originally Posted by eklavya View Post

Do you want to generate 10 numbers like this?
yes
 
Old 06-16-2014, 11:16 PM   #5
sryzdn
Member
 
Registered: Feb 2013
Posts: 274

Original Poster
Rep: Reputation: 9
Hi,

I changed the script as follows:

Quote:
for i in {1..10}; do echo "^\(${RANDOM:0:3}\)? ${RANDOM:0:3}-${RANDOM:0:4)" >> numlist.txt; done
I think the problem of the parantheses is solved ?! But, I don't get anything in "numlist"!!!
 
Old 06-17-2014, 12:06 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I would suggest performing each substring echo individually as you are still not formatting the data correctly.
Code:
echo "^\(${RANDOM:0:3}\)?"
echo "${RANDOM:0:3}"
echo "${RANDOM:0:4)"
Hopefully from here you can see some issues
 
1 members found this post helpful.
Old 06-17-2014, 12:42 AM   #7
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
Are you checking numlist.txt at correct place because it will be created in the directory where you are executing the code.

Your code is working fine for me which you have posted in first post if I change round bracket into curly braces.

Code:
for i in {1..10}; do echo "(${RANDOM:0:3}) ${RANDOM:0:3}-${RANDOM:0:4}" >> numlist.txt; done
 
1 members found this post helpful.
  


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
win32,shell code,shell programming,shell scripting? mr.cracker Linux - Newbie 4 07-12-2013 11:20 PM
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-26-2008 11:50 PM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
javascript validation of ordered list rblampain Programming 0 07-28-2007 04:51 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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