LinuxQuestions.org
Help answer threads with 0 replies.
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 10-11-2012, 03:39 PM   #1
Deke602
LQ Newbie
 
Registered: Oct 2012
Posts: 6

Rep: Reputation: Disabled
Lightbulb Linux Scripting with user input and outputs data from csv file...


Hello I'm working on an extra credit problem for my Linux Operating system management class and I need some kind help which would set me on the right path which I think I am.

Here is the problem and of what I've done so far:

I'm trying to create a simple less than five lines of script which will have user input the city and retrieves the zip and area codes from a csv file which has three fields the first is the zip, name of the city with spaces, and the area codes which are separated by comma.

The output should be the name of the city which the user inputted, zip and area codes for that city. The order doesn't matter.

#!/bin/bash
input="/Deke602/Documents/az.csv"
# Set "," as the field separator using $IFS
# and read line by line using while read combo
echo "What city would you like to know the zip and area codes?"
read city
while IFS=',' read -r f1 f2 f3
do
echo "$f1 $f2 $f3"
done < "$input"

Contents of az.csv file

85640,Agua Linda,520
85320,Aguila,520
85321,Ajo,520
86506,Allentown,928
85920,Alpine,928
85640,Amado,520
85645,Amado,520
85086,Anthem,602
85117,Apache Jct,480
85118,Apache Jct,480
85119,Apache Jct,480
85120,Apache Jct,480
85178,Apache Jct,480
85217,Apache Jct,480
85218,Apache Jct,480
85219,Apache Jct,480
85220,Apache Jct,480
85278,Apache Jct,480
85290,Apache Jct,520
85117,Apache Junction,480
85118,Apache Junction,480
85119,Apache Junction,480
85120,Apache Junction,480
85178,Apache Junction,480
85190,Apache Junction,520
85217,Apache Junction,480
85218,Apache Junction,480
85219,Apache Junction,480
85220,Apache Junction,480
85278,Apache Junction,480
85290,Apache Junction,520

Last edited by Deke602; 10-11-2012 at 05:48 PM.
 
Old 10-11-2012, 05:24 PM   #2
cbtshare
Member
 
Registered: Jul 2009
Posts: 610

Rep: Reputation: 42
We would have to see how the file is formatted
 
Old 10-11-2012, 05:49 PM   #3
Deke602
LQ Newbie
 
Registered: Oct 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Wink Posted contents of csv file

My bad I should have posted a sample of the contents of the file earlier my bad.

Contents of csv file

85640,Agua Linda,520
85320,Aguila,520
85321,Ajo,520
86506,Allentown,928
85920,Alpine,928
85640,Amado,520
85645,Amado,520
85086,Anthem,602
85117,Apache Jct,480
85118,Apache Jct,480
85119,Apache Jct,480
85120,Apache Jct,480
85178,Apache Jct,480
85217,Apache Jct,480
85218,Apache Jct,480
85219,Apache Jct,480
85220,Apache Jct,480
85278,Apache Jct,480
85290,Apache Jct,520
85117,Apache Junction,480
85118,Apache Junction,480
85119,Apache Junction,480
85120,Apache Junction,480
85178,Apache Junction,480
85190,Apache Junction,520
85217,Apache Junction,480
85218,Apache Junction,480
85219,Apache Junction,480
85220,Apache Junction,480
85278,Apache Junction,480
85290,Apache Junction,520
 
  


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
[SOLVED] awk or sed to use CSV as input and XML as template and output to a single file bridrod Linux - Newbie 6 03-13-2012 08:00 PM
Multiple grep outputs appended to single row of CSV file findme.krish Linux - Newbie 5 09-12-2010 07:56 PM
bash scripting... taking user input and adding it to a particular area of a file... dagummit Programming 7 01-13-2010 01:07 AM
Need help on writing data to csv file tucs_123 Linux - Newbie 12 12-29-2008 04:42 AM
help extracting data from csv file willinusf Linux - General 10 10-27-2006 10:10 PM


All times are GMT -5. The time now is 08:10 AM.

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