how to start looping from the second line in .csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to start looping from the second line in .csv file
# 1  
Old 12-11-2008
how to start looping from the second line in .csv file

I have a .csv file and i use the below while loop to navigate through it
But i need to loop from the second line since the first line is the header

How will i do it?? please help

while IFS=, read Filename Path size readonly
do
echo "Filename -> ${Filename}"
echo "Path -> ${Path}"
echo "size -> ${size}"
echo "readonly -> ${readonly}"
done < filenames.csv
# 2  
Old 12-11-2008
may be like this

no_of_line=`wc -l filenames.csv|cut -d' ' -f1`
tail -`expr $no_of_line - 1` filenames.csv | while .....
.
.
.
done
# 3  
Old 12-11-2008
I am geting all the values including header when i do this

My csv file is like this

Filename,Path,size,readonly
file.sh,/File/test,20,Y

I need to retrieve the values from the second line excluding the header

How will i do that ??
# 4  
Old 12-11-2008
May be we can think of writing the logic in awk/nawk...

awk '$0 != "Filename" { print $1,$2,$3,$4 }' filenames.csv

please modify the above logic or syntaxes as per your exact requirement.
# 5  
Old 12-11-2008
Quote:
Originally Posted by schandrakar1
May be we can think of writing the logic in awk/nawk...

awk '$0 != "Filename" { print $1,$2,$3,$4 }' filenames.csv

please modify the above logic or syntaxes as per your exact requirement.
i suggest samll modification in the above code
Code:
 
awk -F"," 'NR>1{print "Filename ->"$1"\nPath ->"$2"\nsize -> "$3"\nreadonly ->"$4}' filename

# 6  
Old 12-11-2008
This awk command works perfect for me. But if i add this as a condition to my while loop its not working as expected

I need a condition which will restrict the header line from geting displayed
while loopingSmilie
# 7  
Old 12-11-2008
why you wanna run this in while loop??
awk will read each line of the file line by line so no need of loop.. and it will exclude the header
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

How to extract start/end times from log file to CSV file?

Hi, I have a log file (log.txt) that which contains lines of date/time. I need to create a script to extract a CSV file (out.csv) that gets all the sequential times (with only 1 minute difference) together by stating the start time and end time of this period. Sample log file (log.txt) ... (7 Replies)
Discussion started by: Mr.Zizo
7 Replies

3. Shell Programming and Scripting

Honey, I broke awk! (duplicate line removal in 30M line 3.7GB csv file)

I have a script that builds a database ~30 million lines, ~3.7 GB .cvs file. After multiple optimzations It takes about 62 min to bring in and parse all the files and used to take 10 min to remove duplicates until I was requested to add another column. I am using the highly optimized awk code: awk... (34 Replies)
Discussion started by: Michael Stora
34 Replies

4. Shell Programming and Scripting

Reading line by line from live log file using while loop and considering only those lines start from

Hi, I want to read a live log file line by line and considering those line which start from time stamp; Below code I am using, which read line but throws an exception when comparing line that does not contain error code tail -F /logs/COMMON-ERROR.log | while read myline; do... (2 Replies)
Discussion started by: ketanraut
2 Replies

5. Shell Programming and Scripting

FILE_ID extraction from file name and save it in CSV file after looping through each folders

FILE_ID extraction from file name and save it in CSV file after looping through each folders My files are located in UNIX Server, i want to extract file_id and file_name from each file .and save it in a CSV file. How do I do that? I have folders in unix environment, directory structure is... (15 Replies)
Discussion started by: princetd001
15 Replies

6. Shell Programming and Scripting

Put a # in start of a specific line of a file

Hello Guys Please let me know how to solve the below issue I have a file like below drop table R1416.ABC1 cascade constraints; drop table R1416.ABC2 cascade constraints; drop table R1416.ABC3 cascade constraints; drop table R1416.ABC4 cascade constraints; drop table R1416.ABC5... (7 Replies)
Discussion started by: Pratik4891
7 Replies

7. Shell Programming and Scripting

How to start reading from the nth line till the last line of a file.

Hi, For my reuirement, I have to read a file from the 2nd line till the last line<EOF>. Say, I have a file as test.txt, which as a header record in the first line followed by records in rest of the lines. for i in `cat test.txt` { echo $i } While doing the above loop, I have read... (5 Replies)
Discussion started by: machomaddy
5 Replies

8. Shell Programming and Scripting

Read csv file line by line

Folks , i want to read a csv file line by line till the end of file and filter the text in the line and append everything into a variable. csv file format is :- trousers:shirts,price,50 jeans:tshirts,rate,60 pants:blazer,costprice,40 etc i want to read the first line and get... (6 Replies)
Discussion started by: venu
6 Replies

9. Shell Programming and Scripting

Looping through each line of text file

Dear all, I have a text file like below. eg.txt abcd efgh ijkl mnop I need a script, which should read the text file eg.txt and assign each line as a parameter. This , i wil use further to pass it a java command to invoke. All inside a for loop Need your help on this. With... (2 Replies)
Discussion started by: KrishnaSaran
2 Replies
Login or Register to Ask a Question