The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Deleting rows that begin with # phil_heath Shell Programming and Scripting 3 08-12-2009 06:24 PM
[HELP] - Delete rows on a CSV file Sadarrab Shell Programming and Scripting 6 06-22-2009 12:21 AM
How to change rows in file - not only patrykxes Shell Programming and Scripting 4 01-26-2009 03:48 PM
deleting rows & columns form a csv file code19 Shell Programming and Scripting 2 03-13-2008 10:06 AM
Deleting the emty rows in a file srivsn Shell Programming and Scripting 7 01-29-2006 05:30 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-30-2009
cobroraj cobroraj is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 20
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 unncessary lines may be different for each files. Data To be deleted are as under:


Yr, Month, Prod
2009, 09, XYX
2008, 04, YYY

Is there any way I can delete these unnecessary lines of each files without opening them individually and manually deleting it?

I Appreciate a help in this.

Regards
  #2 (permalink)  
Old 09-30-2009
theshashi theshashi is offline
Registered User
  
 

Join Date: Aug 2007
Location: Belgium
Posts: 3
sed -e '/Yr, Month, Prod/d' -e '/2009, 09, XYX/d' -e '/2008, 04, YYY/d'
  #3 (permalink)  
Old 09-30-2009
rdcwayx rdcwayx is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 238
need -i option in above sed command.
  #4 (permalink)  
Old 10-01-2009
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
Quote:
Originally Posted by rdcwayx View Post
need -i option in above sed command.
True. But this option should be use with care! No try and error type of thing. Better use the option -i with a suffix like -i.bak which will create an copy of original file, just in case...

theshashi's solution will only work on the sample file given by OP. I understand that the lines following the Yr, Month, Prod line can have different values.

Here is a possible awk solution:
Code:
awk '/Yr, Month, Prod/{f=1}!f' file
Which is shorthand for:
Code:
awk '/Yr, Month, Prod/{f=1}!f{print}' file
  #5 (permalink)  
Old 10-01-2009
edidataguy edidataguy is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 173
Code:
 
sed '/Yr, Month, Prod/', $d' file

Last edited by edidataguy; 10-01-2009 at 02:53 AM..
  #6 (permalink)  
Old 10-01-2009
cobroraj cobroraj is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 20
deleting lines after a specific line

Basically my requirement is to delete all the lines that follows the below mentioned line. ( delete should include the below line also)

Please help

"Yr, Month, Prod"
  #7 (permalink)  
Old 10-01-2009
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
Did you tried the awk and sed solutions given above?

---------- Post updated at 05:46 PM ---------- Previous update was at 05:42 PM ----------

There is a small typo in edidataguy's solution:

Code:
sed '/Yr, Month, Prod/', $d' file
                      ^
# should be

sed '/Yr, Month, Prod/,$d' file
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0