![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| name the column based on symbols in another column | repinementer | Shell Programming and Scripting | 7 | 08-27-2009 12:37 AM |
| Change names in a column based on the symbols in another column | repinementer | Shell Programming and Scripting | 8 | 08-14-2009 03:30 AM |
| column to rows based on another column... | malcomex999 | Shell Programming and Scripting | 5 | 07-08-2009 06:28 AM |
| Changing one column of delimited file column to fixed width column | manneni prakash | Shell Programming and Scripting | 5 | 06-22-2009 05:27 AM |
| how to read the column and print the values under that column | gemini106 | Shell Programming and Scripting | 6 | 03-28-2008 07:05 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Read CSV column value based on column name
Hi All,
I am newbie to Unix I ve got assignment to work in unix can you please help me in this regard There is a sample CSV file "Username", "Password" "John1", "Scot1" "John2", "Scot2" "John3", "Scot3" "John4", "Scot4" If i give the column name as Password and row number as 4 the result I should get ' 'Scot3' can you please help me in writing shell script for the above Thanks John |
|
||||
|
I'm assuming this is homework?
First, do you understand how to pass arguments to your script? Do you know what $1, $2 are inside your script? Next, you need to know how to extract a specific line by number. I realize that the man pages of "sed" are confusing, so to get you going, try Code:
sed -n '4p' You could build a table that matches column names to a number. Your script would have something like Code:
if [ $1 = "Username" ] then Column=1 elif [ $1 = "Password" ] then Column=2 fi echo $Column Code:
read line Wanted=$1 set $line if [ $Wanted = $1 ] then Column=1 ... I hope this gets you started. Let's see you write some code and we can help you over the rough spots. |
|
||||
|
Thank Tony ,
I have tried the following code giving error , please do the needful John.csv is the file name If i give the column name as Password and row number as 4 the result I should get ' 'Scot3' Code:
cat John.csv if [ $1 = "Username" ] then Column=1 elif [ $1 = "Password" ] then Column=2 fi echo $Column read line Wanted=$1 set $line if [ $Wanted = $1 ] then Column=1 else echo "Hello" fi Thanks and Regards, John Last edited by Franklin52; 19 Hours Ago at 06:23 AM.. Reason: Please indent your code and use code tags! |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|