Extract last cell of csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract last cell of csv file
# 1  
Old 03-02-2011
Extract last cell of csv file

How do I extract the last cell in a column of a csv file using linux shell scripting?

Or alternatively, how do I get the number of cells of a csv file?
# 2  
Old 03-02-2011
Something like...

Code:
$ echo a,b,c,d,e,f | awk -F"," '{print "number of fields="NF " and last field is="$NF}'
number of fields=6 and last field is=f

# 3  
Old 03-02-2011
csv implies a comma field delimiter.
Code:
awk -F, '{print $NF}' myfile.csv

The drawback to this is it assumes each row has the same number of fields.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to delete a columns of a CSV file which has cell values with a string enclosed in " , "?

Hi How can I delete a columns from a CSV file which has comma separated value with a string enclosed in double quotes or square bracket and a comma in between? I have a csv file with below format. Template,Target Server,Target Component,Rule Group,Rule,Rule Reference Number,Rule... (7 Replies)
Discussion started by: Litu19
7 Replies

2. UNIX for Dummies Questions & Answers

Trying To Write File Contents To Specfic .csv Cell

Hi, I'm attempting to write the entire contents of a file to a specific .csv cell. So far have only a nawk one liner that will write a value into a specific .csv cell. Trying to use man page but can't seem to get any farther. Any help would be appreciated. nawk -v r=2 -v c=3 -v val=5 -F,... (7 Replies)
Discussion started by: jimmyf
7 Replies

3. Shell Programming and Scripting

How to delete a column/columns of a CSV file which has cell values with a string enclosed in " , "?

How can I delete a column from a CSV file which has comma separated value with a string enclosed in double quotes and a comma in between? I have a file 44.csv with 4 lines including the header like the below format: column1, column2, column3, column 4, column5, column6 12,455,"string with... (6 Replies)
Discussion started by: dhruuv369
6 Replies

4. UNIX for Advanced & Expert Users

How to extract data from single first cell and copy it notepad?

how to extract data from single first cell and copy it notepad sample source IN EXCEL DD-MM-YYYY LOANNUM LOANPARTID OUTPUT IN NOTEPAD DD-MM-YYYY I WANT ALONE DATE SHOULD BE EXTRACTED FROM EXCEL AND COPY IT IN NOTEPAD CAN ANYONE HELP REGARDING THIS USING SCRIPTS (2 Replies)
Discussion started by: gchandu
2 Replies

5. Shell Programming and Scripting

How to create multiline csv cell through shell script?

Hi, I have a text like the one given below status="Observation 1" read1="Source rows not load" read2="Score drop" I want to create a csv and mail it out in such a way that all three lines will be in a single cell but as three lines. For ex Col C1 ... (3 Replies)
Discussion started by: prasperl
3 Replies

6. UNIX for Dummies Questions & Answers

Need help combining txt files w/ multiple lines into csv single cell - also need data merge

:confused:Hello -- i just joined the forums. I am a complete noob -- only about 1 week into learning how to program anything... and starting with linux. I am working in Linux terminal. I have a folder with a bunch of txt files. Each file has several lines of html code. I want to combine... (2 Replies)
Discussion started by: jetsetter
2 Replies

7. Shell Programming and Scripting

extract pattern from csv file

hi, i have a situation where i have a csv file in the format date,name eg: 1284631889869,a 1284631889879,b 1284631889459,c . . . . . . . now i take a time and an interval from user. (5 Replies)
Discussion started by: niteesh_!7
5 Replies

8. UNIX for Advanced & Expert Users

How to add two values in the same cell of CSV file

I need help to create a csv file with Unix command. In csv file, i need to put two values in the same cell. Rite now, whts happening is, if i put 2 values in the same cell, its comming as " asd, zxc" but i want it in different line but in same cell. asd zxc Please reply me ASAP. (1 Reply)
Discussion started by: Prashant Jain
1 Replies

9. Shell Programming and Scripting

extract .csv file

Hi all I am new to unix . I need to write a script that extracts some data from oracle into a .csv file with heading of the columns in the file SO i created the following two scripts but they are not working ac.sql (this is the sql file that i will call inside the shell script when i run... (1 Reply)
Discussion started by: rajesh_tns
1 Replies

10. Shell Programming and Scripting

How to edit particular cell of csv file using shell script

I have one csv file and in that I want update particular cell. I know the row and coloumn number for that respective. Please help me... (6 Replies)
Discussion started by: deepak_p86
6 Replies
Login or Register to Ask a Question