LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 01:01 AM   #1
sryzdn
Member
 
Registered: Feb 2013
Posts: 273

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, 03:59 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,361
Blog Entries: 55

Rep: Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547
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, 09:26 AM   #3
eklavya
Member
 
Registered: Mar 2013
Posts: 622

Rep: Reputation: 136Reputation: 136
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, 10:37 AM   #4
sryzdn
Member
 
Registered: Feb 2013
Posts: 273

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

Do you want to generate 10 numbers like this?
yes
 
Old 06-17-2014, 12:16 AM   #5
sryzdn
Member
 
Registered: Feb 2013
Posts: 273

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, 01:06 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,563

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
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, 01:42 AM   #7
eklavya
Member
 
Registered: Mar 2013
Posts: 622

Rep: Reputation: 136Reputation: 136
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


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
win32,shell code,shell programming,shell scripting? mr.cracker Linux - Newbie 4 07-13-2013 12:20 AM
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-27-2008 12:50 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
javascript validation of ordered list rblampain Programming 0 07-28-2007 05:51 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM

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

All times are GMT -5. The time now is 06:15 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration