Displaying specific lines from a CSV file

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Displaying specific lines from a CSV file
# 1  
Old 01-26-2010
Question Displaying specific lines from a CSV file

1. The problem statement, all variables and given/known data:
Display from a csv file, birthdays that occur today. If there are no birthdays today, the next one in the year.


2. Relevant commands, code, scripts, algorithms:
The csv file is ordered from older to younger (ie. the most recent birth is at the bottom of the list).


3. The attempts at a solution (include all code and scripts):
I can pull todays birthdays out by the following;
Code:
date=`date +"%m"`/`date +"%d"`
cat birthdays.csv | grep $date

However I'm having trouble finding where to start to echo the next birthday if there isn't one today. The CSV file has to be ordered as stated above.

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Canterbury Christ Church University, Canterbury, UK, Paul Stephens, BSc Forensic Computing (Operating Systems 1)

Any help would be greatly appreciated!

Cheers,
Adzi

Last edited by Adzi; 01-26-2010 at 02:45 PM.. Reason: Adding additional course info.
# 2  
Old 01-26-2010
Increment the date, do another grep if still no output then increment it again?
# 3  
Old 02-02-2010
How do I check if the out put is null?

I'm used to other languages such as VB etc so a logical port for me would be to do
Code:
if
$variable is null then
$date + 1
fi

However I'm pretty sure implementing this would give me horrible errors. So what would be the way to do this in linux/sage?

Many Thanks,
Adzi
# 4  
Old 02-02-2010
Bourne, Korn and Bash compatible code:
Code:
if [ -z "${VARIABLE}" ]; then
  echo "VARIABLE is empty."
fi

# 5  
Old 02-03-2010
From what I understand (I may be wrong for Im more french speaking native...):
your csv file has birth dates in sorted from older to most recent.
your code could show up a todays birthday if present but in no way help you find the next...
one possible way to start would be to sort the file on months (1rst) and day (2nd) (but are you allowed?)

looks like you will have to write an algorithm with a couple of loops...
# 6  
Old 02-03-2010
Thanks for the replies. The CSV file is ordered by day and month now, listed as such...
Code:
name,telNo,birthday
test 1,123456789,1989/01/26
test 2,123456789,1986/01/27
test 3,123456789,1989/06/09
test 4,123456789,1901/08/15

Which means I should be able to get the next line by performing a simple iteration and adding one to the date field. I cant seem to get this to work. My bash logic isn't fantastic and there is probably a lot of glaring errors but this is what I have (which isn't working)...

Code:
#"/bin/bash
date=`date +"%m"`/`date +"%d"`
if [ -z "`cat birthday.csv | grep $date`" ]; then
$newDate=$date+1
$date=$newDate
else
echo cat birthday.csv | grep $date
fi

Am I going about this completely the wrong way?
# 7  
Old 02-03-2010
You dont find a birthday that matches today, then what?
You are to write an algorithm using a loop (e.g. while....) until you find the next date after hoping you are not at EOF...

remember your will have to deal with changing months with your increment....

Good luck
Courage!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert a horizontal lines to vertical lines in a csv file

Hi.. I need some help in converting the below horizontal lines to vertical lines format. can anyone help me on this. input file Hour,1,2,3,4,5 90RT,106,111,111,112,111 output file Hour,90RT 1,106 2,111 3,111 4,112 5,111 (3 Replies)
Discussion started by: Raghuram717
3 Replies

2. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

3. Shell Programming and Scripting

insert data into specific lines of a CSV

So I work in a 1 to 1 laptop deployment and sometimes we need to mass order parts. The vendor will send us a text file and we have to manually input serial numbers. Well I have a full blown web based inventory system which I can pull serial number reports from. I then have to input the part... (4 Replies)
Discussion started by: tlarkin
4 Replies

4. Shell Programming and Scripting

Displaying lines of a file which have the highest number?

Hello Wondering if anybody may be able to advise on how I can filter the contents of the following file: <object_name>-<version> <Instance> GM_GUI_code.fmb-4 1 GM_GUI_code.fmb-5 1 GM_GUI_code.fmx-4 ... (7 Replies)
Discussion started by: Glyn_Mo
7 Replies

5. Shell Programming and Scripting

Displaying lines of a file where the second field matches a pattern

Howdy. I know this is most likely possible using sed or awk or grep, most likely a combination of them together, but how would one go about running a grep like command on a file where you only try to match your pattern to the second field in a line, space delimited? Example: You are... (3 Replies)
Discussion started by: LordJezoX
3 Replies

6. UNIX for Dummies Questions & Answers

Displaying specific columns in a file

Hi, I'm just wondering how you display a specific set of columns of a specified file in Unix. For example, if you had an AddressBook file that stores the Names, Phone numbers, and Addresses of people the user entered in the following format (the numbers are just to give an idea of what column... (1 Reply)
Discussion started by: logorob
1 Replies

7. Shell Programming and Scripting

Displaying number of lines from file

Hi, I am using below command to display the number of line, but its returning no of lines along with file name. But i want only no of line in the variable p. Please help me on this? p=`wc -l "text file"` echo "$p" (6 Replies)
Discussion started by: shivanete
6 Replies

8. UNIX for Dummies Questions & Answers

how to display specific lines of a specific file

are there any basic commands that can display lines 99 - 101 of the /etc/passwd file? I'm thinking use of head and tail, but I forget what numbers to use and where to put /etc/passwd in the command. (2 Replies)
Discussion started by: raidkridley
2 Replies

9. Shell Programming and Scripting

Displaying the Last Modification Time of a specific file

How can I get and display the last modification time of a file? in scripting or specifically using Batch file I want this info for me to determine whether an image has been edited or not by using the last modification time and compare it to our stored date of modification. can somebody help... (5 Replies)
Discussion started by: jaque18
5 Replies

10. UNIX for Dummies Questions & Answers

Displaying specific lines in a file.

I'm trying to figure out how to display a certain line in a text file. I keep getting references to Tail and Head, and I know how these work, but i'm lost on how to find say the third out of the five lines and display only that. I thought maybe grep could help, but that doesn't seem likely. ... (3 Replies)
Discussion started by: MaestroRage
3 Replies
Login or Register to Ask a Question