LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 12-21-2011, 11:14 AM   #1
smks
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Rep: Reputation: Disabled
Smile Putty using csv files in BASH to format file in script as output


Hello I want to make a bash script that when you execute it it does the following:

Completed steps:

1)asks for username, age and location. (done with read and echo (please enter)
2)takes the seperate variables and outputs them to a file called details.csv (done also with
echo "${name1#*=}, ${age1#*=}, ${location#*=}" >> details.csv)
Uncomplete steps:

3) create headers for the 3 elements to display at top of page but not repeat
like this Name | Age | Location
john | 22 | surrey
with obvious normal formatting.

4) sort these by age and output in bash.
_________________________________________________________________________________

Any ideas?

Many thanks
 
Old 12-21-2011, 01:06 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Quote:
Originally Posted by smks View Post
create headers for the 3 elements to display at top of page but not repeat
You mean "echo once before displaying loop data" or do you mean "stay visible while loop data output scrolls"?


Quote:
Originally Posted by smks View Post
sort these by age and output in bash.
So what problem do you have with 'sort' you can't fix? Posting (pseudo) code helps.
 
Old 12-21-2011, 01:17 PM   #3
smks
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
I mean when the new csv file is created. have the names of the columns like name, age and location along the top. so when i use bash to add elements to the file it doesnt have multiple entries saying name, age, location rather it stays at top but then never repeats itself?

and with the sort thing I mean I do not know how to sort the entries into a table to bash whatsoever. i cant think of ne pseudo code that would do it?

thanks
 
Old 12-21-2011, 06:44 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Show us what you've got so far.
Also, I recommend using the same separators in the header rec as the data rec, for simplicity of parsing back later.
I'm assuming you want a data file like
Code:
Name,Age,Location
john,22,surrey
jane,23,sussex
 
Old 12-21-2011, 08:19 PM   #5
smks
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
#!/bin/bash
#**********
#Question3

echo To create a file please enter the following details
sleep 2

echo Please enter your name:
read name1

echo Please enter your age:
read number1

echo please enter location:
read DOB1

echo "${name1#*=}, ${age1#*=}, ${location#*=}" >> details.csv
sed -i 'Name, Number, DOB'

__________________________________

this is it so far. it creates a csv file in same directory. I just want to practise manipulating and formatting information from files and using it in a bash script.
I then want to sort them by age in bash as an output.

not much to ask i hope

thanks
 
Old 12-22-2011, 01:13 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Is the example I created correct : better show us an example output file you want.
also
Code:
echo please enter location:
read DOB1
is inconsistent: location OR date of birth ??? If the latter, what format?
 
Old 12-22-2011, 05:13 PM   #7
smks
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
apologies i meant the variable to be location1 not DOB1.
 
Old 12-22-2011, 06:50 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Change the top of your prog to
Code:
#!/bin/bash
set -xv
and re-run it; it'll show you what some of the probs are eg number1 v age1 etc ...

Also,
Code:
echo "$name, $age, $location" >> info.dat
 
  


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
bash script choice menu from csv file deefke Linux - Newbie 5 01-25-2011 02:31 PM
Update csv file into mysql db via bash script xmrkite Linux - Software 4 01-13-2010 01:43 AM
[SOLVED] Need help create a bash script to edit CSV File imkornhulio Programming 13 02-05-2009 11:23 AM
Combine output of multiple files in one CSV file say_hi_ravi Programming 4 07-17-2008 04:04 AM
bash script - remove header row from csv file pljvaldez Programming 5 08-30-2006 12:05 PM


All times are GMT -5. The time now is 10:43 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration