File Field Replacement, Assigning Fields to Variables, Lists/Arrays?
Okay, I've made threads on extracting fields and comparing strings in separate files in .csv's. I've written the following code with intentions of learning more.
I just want this one question answered: How can I assign fields from a file(comma separated) to variables?
My goal is to check whether or not a user is driving a car. If he is, he will not be capable of driving others. If he is not, he will be capable of driving one.
So first off, here's a sample cars.csv file I made: The fields separated by commas represent ID number of driver, car model, brand, make, and a boolean 0/1 to see whether or not the car is being driven, respectively.
Next, here is a sample drivers.csv listing the drivers: The fields in this file are ID number of driver, name of driver, and a boolean 0/1 to check if the user is driving a car, respectively.
This file, garage.sh allows the user to be selected. I used case for the first part as I don't know how to do what I am asking for..yet.
Okay, so what I want to do is try select a driver and select a command. I don't want to ask how to do a lot as I want to learn to do the others from what you tell me.
So, for example, I could compare the IDnum in cars.csv with the IDnum in drivers.csv and output it with something like this: Question 1:
How would I do the above comparison but assign all fields to different variables? (ie. $model=1.2, $year=1.4, etc)
Quote:
Question 2:
How would I make it output a list to the screen like the one below and allow users to select which car to drive(preferably using case so the code flows)? Figured this one out on my own using the following:
Still need to know how to set things to values and write them back in
Quote:
Question 3:
Conversely to question 1, how would I write/replace fields in the .csv's with variables in the script? (I think I could do it using sed?)
EDIT: I think I can just use -tr...but we'll see
Last edited by chickeneaterguy; 02-20-2011 at 05:21 AM..
Hi,
I'm trying to assign the permissions, owner and group of a file to seperate variables, but using
ls -l filename | awk '{print $1 "\t" $3 "\t" $4}'
gives the owner as tom.ja instead of tom.james
Is there any way to expand it so i get the full name, or is there an easier way to get them... (5 Replies)
Hi All,
I have a problem assigning variables to script.I have a script in which i have a while loop now i have to assign some values obtained to an array which will be used later in the script.Can anyone help how to do that.
At present my scrot looks like:
co=0
pco=0
co=`cat /tmp/highcpu... (4 Replies)
Hello everybody, this is my first post here, I think IŽll be here for a long time :D
I wanted to know how I can assign each single character from a string to an array...
For example, "unix"
I have to set,
array=u
array=n
array=i
array=x
However, that string may change in each... (5 Replies)
suppose I have a file named abc.txt.The contents of the file is sited below
abc.txt
maitree,test,test3
Using awk command can I store these 3 values in 3 different variable and in one single line command of awk.
suppose variable a b c is there.
I don't want like this
a=`awk -F"," '{print... (2 Replies)
I am looking to create a perl script which will take numbers from a simple text file, convert them from decimal to hex, and then rewrite those values in the file or create a new file with the hex numbers(whichever's easier).
My text document for example would be something as simple as
1312... (6 Replies)
Problem
Part 1.
Gather data from linux server and output to a file named data_DDMMYY
Output file must contain the file name and size
Part 2.
Compare todays data_DDMMYY to yesterdays data_DDMMYY and output results to a file named difference_DDMMYY
Output file must show the difference in... (3 Replies)
Hi! This might be a simple thing, but I'm struggling to assign values to variables from the file.
I've the following values stored in the file.. It consists of only two rows..
10
20
I want to assign the first row value to variable "n1" and the second row value to variable "n2"..
That is ... (3 Replies)
I have a file that has four values on each line and I'd like to give each column a variable name and then use those values in each step of a loop. In bash, I believe you could use a while loop to do this or possibly a cat command, but I am super new to programming and I'm having trouble decoding... (2 Replies)
So first: Sorry if the title is confusing...
I have a script I'm writing with a file with several names in it (some other info - but it's not really pertinent...) - I want to be allow the user to delete certain records, but I ran into a problem I'm not sure how to go about fixing.
If I were... (6 Replies)