LinuxQuestions.org
Help answer threads with 0 replies.
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 08-15-2011, 07:14 PM   #1
puriandrua
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Rep: Reputation: Disabled
User Input


Hello, I'm Puriandrua and I'm new to the forums. I just had a simple quick question..

So I've completed a lab for a linux programming class I'm working on and looking at doing the extra credit which is taking input from the user in the .bat file I've created after slimming the file down and everything. Basically if the user inputs age 18 the .bat file will change it to 27 and eliminate or disallow any users named Chris.

Can anyone help me with getting started or show me how to take user input in the .bat file? The code I have for my .bat file thus far is the following:

Code:
grep Columbus custFile.txt | grep -v Chris | awk -F"," '{OFS="|"}{print$2,$1,$3,$4}' | sed 's/18/27/g' > import.txt
I'm not sure how to go about accepting user input :/

Thanks in advance,
Puriandrua
 
Old 08-15-2011, 07:17 PM   #2
puriandrua
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Basically what it's doing so far is taking grabbing the file custFile.txt with only the columns that have 'Columbus' and then eliminating all of the 'Chris's' in the file, and changing the commas to pipes and I've eliminated the 5th column as it is of no use to what I'm doing, then change all age '18's to 27's and submitting it to a document called import.txt..
 
Old 08-15-2011, 07:20 PM   #3
puriandrua
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Oh, and basically what I'm looking for is when the script is run it should as the user something along the lines of "Would you like to filter a city?" and if the user answers yes, the script should ask what city they want to filter, otherwise if the user says no, then leave it alone.
 
Old 08-15-2011, 08:30 PM   #4
puriandrua
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
ok I've decided to use it as an if then statement.

Code:
echo -n "Would you like to filter a city?"
read -e userInput
grep -i "$userInput"

If $userInput == yes;
then

echo -n "What city would you like to filter?"
read -e cityToFilter
grep -i "$cityToFilter"

grep Columbus custFile.txt | grep -v Chris | grep -v $cityToFilter | awk -F"," '{OFS="|"}{print$2,$1,$3,$4}' | sed 's/18/27/g' > import.txt

else

grep Columbus custFile.txt | grep -v Chris | awk -F"," '{OFS="|"}{print$2,$1,$3,$4}' | sed 's/18/27/g' > import.txt

fi
anyone see where my error is that it's not reading through and performing the option?
 
Old 08-15-2011, 11:42 PM   #5
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'll answer with a question, can you tell me what the following line is doing (in your mind):
Code:
grep -i "$userInput"
 
  


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
Verify User Input nkitmitto Programming 8 07-15-2010 02:03 AM
User input into Bash scripts and checking validity of user input?? helptonewbie Programming 8 07-07-2008 06:40 PM
Bash Y/N user input zcrxsir88 Programming 11 04-16-2008 11:35 AM
check user input for IP ilnli Programming 7 08-08-2007 06:42 PM
validating user input blanks Programming 3 09-02-2004 03:47 PM

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

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