skip first line when doing a read of csv file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers skip first line when doing a read of csv file
# 1  
Old 11-07-2011
skip first line when doing a read of csv file

Folks,
how do i skip the first line in a csv, while doing the read of a csv file in to a variable line by line.
eg :

do

echo $line

done < $rpt

where rpt is path to csv file

The initial 1st line is a garbage that i want to avoid, and start reading from 2nd line

Thanks

Venu
# 2  
Old 11-07-2011
Easiest way is to use sed:

Code:
sed 1d $rpt | while read d
do
   echo $d
done

The 1d causes the first line to be deleted and sed writes the rest to stdout.
This User Gave Thanks to agama For This Post:
# 3  
Old 11-07-2011
Since you are using a while loop, try this...
Code:
#!/bin/bash

i=1
while read line
do
        test $i -eq 1 && ((i=i+1)) && continue
        echo $line
done < infile

Using AWK
Code:
awk 'NR>1' infile

HTH
--ahamed
This User Gave Thanks to ahamed101 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read .csv file

Hello, this is my very first comment on this forum and i hope i don't mess it up. If i do, please forgive me (also for any language mistakes you may wanna know that i'm not native speaking). As i just started doing a bigger paper for my studies i got a bunch of data in seperate csv-files... (1 Reply)
Discussion started by: FabianDe
1 Replies

2. UNIX for Advanced & Expert Users

Read file and skip the line starting with #

Hi all, I'm new in unix. Need some help here. I have a file called server.cfg which contains the servers name, if I don't want to run on that server, I'll put a "#" infront it. username1@hostname.com username2@hostname.com #username3@hostname.com #username4@hostname.com... (17 Replies)
Discussion started by: beezy
17 Replies

3. Shell Programming and Scripting

want to skip a line in XML file using awk

HI All, I am trying to split a xml using awk. now the issue is i want to skip three lines from the xml file. first two and last one based on pattern. plz some one help. i am new to awk and struggling :wall: <?xml version="1.0"?> <notification> ..... ..... ..... ..... ........ (24 Replies)
Discussion started by: ganesan kulasek
24 Replies

4. UNIX for Dummies Questions & Answers

When reading a csv file, counter to read 20 lines and wait for minute then read next 20 till end

Hello All, i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file. Any inputs are appreciated ... (3 Replies)
Discussion started by: victor.s
3 Replies

5. 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

6. Shell Programming and Scripting

read .csv file

Need UNIX script read below .csv file and print the line only records where type = TRN. Srno,Type,InputFileName,NewColumnData 1,TRN,File1.dat,11 2,TRN,File2.dat,12 3,TRN,File3.dat,13 4,REF,File4.dat, 5,REF,File5.dat, regards, santosh (4 Replies)
Discussion started by: santosh2k2
4 Replies

7. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

8. Shell Programming and Scripting

Read Csv file

Hi All, I need to check if a csv file is empty, leaving the first line as the first line is header pls help Thanks (3 Replies)
Discussion started by: gwrm
3 Replies

9. UNIX for Dummies Questions & Answers

How to skip first line from a file while manupulating the file

I need to put single quotes on the columns of a .csv file. The first row contains the column headers. I need to skip the first row and put quotes for rest of the rows. Would please someone help me with this. Thanks JP (4 Replies)
Discussion started by: JPalt
4 Replies

10. UNIX for Dummies Questions & Answers

read a line from a csv file and convert a column to all caps

Hello experts, I am trying to read a line from a csv file that contains '.doc' and print the second column in all caps. e.g. My csv file contains: Test.doc|This is a Test|test1|tes,t2|test-3 Test2.pdf|This is a Second Test| test1|tes,t2|t-est3 while read line do echo "$line" |... (3 Replies)
Discussion started by: orahi001
3 Replies
Login or Register to Ask a Question