![]() |
|
|
google unix.com
|
|||||||
| Forums | Casino | Register | Forum Rules | Links | Albums | FAQ | Members List | 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 |
| Removing Blank Lines | dhanamurthy | Shell Programming and Scripting | 3 | 05-08-2008 01:52 AM |
| How to count lines - ignoring blank lines and commented lines | kthatch | UNIX for Dummies Questions & Answers | 6 | 05-25-2007 01:21 AM |
| removing duplicate lines from a file | ocelot | UNIX for Dummies Questions & Answers | 4 | 01-25-2007 10:02 AM |
| Removing duplicate lines ignore case | hellsd | UNIX for Dummies Questions & Answers | 17 | 12-02-2004 09:47 AM |
| delete blank lines or lines with spaces only | vascobrito | UNIX for Dummies Questions & Answers | 3 | 01-13-2004 06:36 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
removing duplicate blank lines
Hi,
how to remove the blank lines from the file only If we have more than one blank line. thanks rameez |
| Sponsored Links |
|
|||
|
The variable blank will be zero initially, but non-zero (i.e. true) on subsequent runs.
The 1 is an awk idiom which matches and prints lines not handled by previous conditions. Actually you should change it to '{ blank=0; print }' in order for the script to work correctly on files where there are multiple sequences of adjacent empty lines. Sorry for missing that. |
|
|||
|
Sorry, it's still not right. Should test before I post. Apologies.
Code:
awk '/^$/{ if (! blank++) print; next } { blank=0; print }'file
|
|||
| Google The UNIX and Linux Forums |
![]() |
| Bookmarks |
| Tags |
| duplicates, truncation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|