Delete first line of a csv file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Delete first line of a csv file
# 1  
Old 07-06-2011
Delete first line of a csv file

Hi there
How do I delete the first line of a csv file without creating a new file ?
Regards,
Peter
# 2  
Old 07-06-2011
With GNU sed...
Code:
sed -i 1d file1.csv

With awk...
Code:
awk '{a[NR]=$0}END{for(i=2;i<=NR;i++)print a[i]>FILENAME}' file1.csv

# 3  
Old 07-07-2011
Quote:
Originally Posted by Ygor
With GNU sed...
Code:
sed -i 1d file1.csv

With awk...
Code:
awk '{a[NR]=$0}END{for(i=2;i<=NR;i++)print a[i]>FILENAME}' file1.csv

what is the need for '>FILENAME' here? I am getting the output only if it is not present.
# 4  
Old 07-11-2011
Quote:
Originally Posted by royalibrahim
what is the need for '>FILENAME' here? I am getting the output only if it is not present.
Got it!! its a redirection to the same file. Thanks Smilie But, a doubt, in most of the shell command if we tend to redirect the output to the same active file from which the input data is coming from, then that file will be emptied (NULL) usually. How come it is exceptional here?
# 5  
Old 07-11-2011
In the END{} rule, the file is closed but the FILENAME variable is still set.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to delete row in csv file on date range?

I want to delete row in csv file , which row value from 2009-10-01 to 2011-06-03 using script.my csv row data look like: 2009-10-01 2011-03-30 2011-03-31 2011-04-01 2011-06-03 2011-06-30 2011-07-01 2011-09-28 ... (7 Replies)
Discussion started by: rakibul639
7 Replies

2. Shell Programming and Scripting

Need Help to delete carriage return and new line in csv file

Hi All, I have a problem loading the data from a csv file As you see below in the Input ,For the Data starting with " there are 2 lines, which i want to make them into single without changing the format of that data. You can see the desired output below: While i try to open the csv file and... (4 Replies)
Discussion started by: mlavanya
4 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

Delete Description column from a csv file

Hi Friends, I have a scenario where in I need to implement the following logics. 1. Delete a column named "DESCRIPTION'" from a csv file(sample.csv). 2. Move "CURRENT_SALES" column to 10th position in columns from the same file. Thanks in Advance, Pons (10 Replies)
Discussion started by: ponnst
10 Replies

5. UNIX for Dummies Questions & Answers

using sed delete a line from csv file based on specific data in two separate fields

Hello, :wall: I have a 12 column csv file. I wish to delete the entire line if column 7 = hello and column 12 = goodbye. I have tried everything that I can find in all of my ref books. I know this does not work /^*,*,*,*,*,*,"hello",*,*,*,*,"goodbye"/d Any ideas? Thanks Please... (2 Replies)
Discussion started by: Chris Eagleson
2 Replies

6. Shell Programming and Scripting

delete a row in csv file based on the date

Hi, I have a csv file with old data..i need to have only last 30 days from the current dateof data in the file.The fourth field in the file is a date field.i need to write a script to delete the old data by comparing the the fourth field with the (current date -30).I need to delete the rows in... (2 Replies)
Discussion started by: pals70423
2 Replies

7. Shell Programming and Scripting

How to Delete Last Row from .csv file in perl

Hi , I've a perl script to convert .xls to .csv .After conversion I want to delete first 28 and the last row from .csv file.Is there any efficent way to achive this both together. I'm deleting first 28 rows by using folllowing my perl code: exec " tail -n+28 infile.csv > outfile.csv ... (7 Replies)
Discussion started by: ajaypatil_am
7 Replies

8. Shell Programming and Scripting

[HELP] - Delete rows on a CSV file

Hello to all members, I am very new in unix stuff (shell scripting), but a want to learn a lot. I am a ex windows user but now i am absolutely Linux super user... :D So i am tryng to made a function to do this: I have two csv files only with numbers, the first one a have: 1 2 3 4 5... (6 Replies)
Discussion started by: Sadarrab
6 Replies

9. UNIX for Dummies Questions & Answers

Delete first row of csv file

I have a csv file, which is > 2 Gigs. I need to BCP that file to Sybase db , but I cant upload that b'caz first row of the file is failing. ( having some errors probably.) I can manually insert the first line into db & then I can upload the rest of the data in file, if i can delete the first row. ... (2 Replies)
Discussion started by: kedar.mehta
2 Replies

10. UNIX for Dummies Questions & Answers

How to delete a record from a csv file

Hi Guys I have downloaded a table from oracle database in .csv format. it has many fields as Title, First Name, Last Name etc. I have to download distinct titles from database and now i have to check all those titles from data of First Name one by one. and then i have to delete matched record.... (1 Reply)
Discussion started by: Rajeev Agrawal
1 Replies
Login or Register to Ask a Question