LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   User Input (https://www.linuxquestions.org/questions/linux-newbie-8/user-input-897502/)

puriandrua 08-15-2011 07:14 PM

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

puriandrua 08-15-2011 07:17 PM

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..

puriandrua 08-15-2011 07:20 PM

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.

puriandrua 08-15-2011 08:30 PM

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?

grail 08-15-2011 11:42 PM

I'll answer with a question, can you tell me what the following line is doing (in your mind):
Code:

grep -i "$userInput"


All times are GMT -5. The time now is 06:42 PM.