How to remove Blank rows in a csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove Blank rows in a csv file
# 1  
Old 01-12-2011
Question How to remove Blank rows in a csv file

Hi,
I need help to remove blank rows at the end of file.

Sample data:
Code:
"Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91
"Tønsberg, Brygga Kino SF",Tønsberg,202-1,Tønsberg SF 4,202-1-4
,,,,
,,,,
,,,,
,,,,

Expected data:
Code:
"Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91
"Tønsberg, Brygga Kino SF",Tønsberg,202-1,Tønsberg SF 4,202-1-4


Last edited by Franklin52; 01-12-2011 at 02:05 PM.. Reason: Please use code tags
# 2  
Old 01-12-2011
Code:
awk -F, 'length>NF+1' file

# 3  
Old 01-12-2011
Code:
grep -vx ,,,, file

# 4  
Old 01-12-2011
Code:
 awk '!/^,,,,/' file

# 5  
Old 01-12-2011
That needs a $ sign too, no?
Code:
awk '!/^,,,,$/' file

---
One more:
Code:
awk -F[^,] NF-1 file

Code:
awk NF-4 FS= file

Code:
grep '[^,]' file

Code:
grep ..... file

Code:
awk /[^,]/ file


Last edited by Scrutinizer; 01-12-2011 at 09:25 PM..
# 6  
Old 01-12-2011
you forgot to add sed :)
Code:
sed -n '/[^,]/p' file

# 7  
Old 01-13-2011
MySQL

Hi Experts,
solution from Franklin works for me
awk -F, 'length>NF+1' file


Thanks to everyone
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get duplicate rows from a csv file

How can i get the duplicates rows from a file using unix, for example i have data like a,1 b,2 c,3 d,4 a,1 c,3 e,5 i want output to be like a,1 c,3 (4 Replies)
Discussion started by: ggupta
4 Replies

2. Shell Programming and Scripting

[bash] - Replace blank and string in csv file

Hi all, i have a .csv file with only two columns, like: Login;Status Luca;S Marco; Stefano; Elettra;S Laura; ... I need to replace the blank space on Status column whit Enabled end, on the same column, S whit Disabled, like: Login;Status Luca;Disabled Marco;Enabled Stefano;Enabled... (10 Replies)
Discussion started by: kamose
10 Replies

3. Shell Programming and Scripting

Detect blank spaces in a CSV file

I'm monitoring a WLAN network to keep track of new SSIDs popping up. The SSIDs are stored along with the AP MAC address and a few other parameters in a CSV file. A typical line could look like this: 18:70:9f:e3:80:aa 10:11:15 MyNetwork 2437 Now, the problem is that some networks use SSIDs... (4 Replies)
Discussion started by: Zooma
4 Replies

4. Shell Programming and Scripting

Inserting blank columns in already present CSV file

Hi, i have a csv file which have headers and values of it like below : headers --> CI Ref SerialNumber LastScanDate values --> VMware-42,VMware-42,Tue, 20 May 2014 11:03:44 +0000 i want to have a above csv in below format : headers --> CI Name CI Description CI Ref... (6 Replies)
Discussion started by: omkar.jadhav
6 Replies

5. Shell Programming and Scripting

Need to remove a selection of rows separated by blank lines

hello, here is an example: 9.07 9.05 0.00 2.28 0.00 0.08 1.93 3.62 10.97 12.03 12.03 0.00 2.73 0.00 0.07 (3 Replies)
Discussion started by: Baron1
3 Replies

6. Shell Programming and Scripting

Copying down first row in to all the below blank rows in a .csv file

Hi All, I have many of files(.csv) of the format given below. Date,Name,Location 04/02/2012,A,India ,B,China ,C,USA Like this I have 1000's of rows and many columns in all my files. I need a shell script to copy down the Date(in this example column1) to the next 2 rows below(in the... (8 Replies)
Discussion started by: ks_reddy
8 Replies

7. Shell Programming and Scripting

Remove Blank Rows

Hello All, I am having a problem in automating my UNIX Script to remove the blank spaces in between records. When I incorporate it into my script, the output file is deleting the whole content :confused: Basically this is what I am trying to do: File contains data like this:... (14 Replies)
Discussion started by: Vinsanity
14 Replies

8. Shell Programming and Scripting

Deleting rows from csv file

Hello, I am supposed to process about 100 csv files. But these files have some extra lines at the bottom of the file. these extra lines start with a header for each column and then some values below. These lines are actually a summary of the actual data and not supposed to be processed. These... (8 Replies)
Discussion started by: cobroraj
8 Replies

9. Shell Programming and Scripting

how to delete blank rows in a log file

Help How to delete all blank rows in log file (4 Replies)
Discussion started by: suryanarayana
4 Replies

10. Solaris

finding & replacing blank rows/spaces in a file

Can anyone help me find and replace blank rows in a file with a numeric value (ie blankrow=someTxtOrNumValue), the file is over 500,000 rows long so it would need to be the quickest way as I'll need to do this for multiple files...I would be greatfull for any suggestions....thanks sample file:... (2 Replies)
Discussion started by: Gerry405
2 Replies
Login or Register to Ask a Question