![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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
Code:
awk '/Yr, Month, Prod/{f=1}!f{print}' file
|
|
||||
|
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
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|