|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi All, How do i remove continuos blank lines from a file. I have a file with data: Code:
abc; def; ghi; jkl; mno; pqr; In the above file, there are two blank lines. I want to remove, one out of them. My output should look like: Code:
abc; def; ghi; jkl; mno; pqr; With the below command, all the blank lines are getting deleted. I don't want that. I have to remove one out of two blanks. Code:
sed -i '/^$/d' my_file |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Try like... Code:
awk 'NF>0' test.txt |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
The above command is removing all the blank lines. But i want to keep only one blank line if more than one blank lines avail. I want to remove all other blank lines. ---------- Post updated at 06:22 PM ---------- Previous update was at 06:17 PM ---------- Code:
awk '/^$/{ if (! blank++) print; next } { blank=0; print }' my_fileor Code:
awk 'NR==1 || NF || prvNF {print} {prvNF=NF}' my_fileAny of the above codes are working fine for me.. Thank you all!!!!!!! |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Removing blank lines not working | MaindotC | UNIX for Dummies Questions & Answers | 12 | 08-20-2012 09:00 AM |
| Removing blank lines in a file | ashok.k | UNIX for Dummies Questions & Answers | 3 | 04-27-2010 02:56 AM |
| Removing blank lines from comma seperated and space seperated file. | pinnacle | Shell Programming and Scripting | 11 | 05-08-2009 11:58 AM |
| removing duplicate blank lines | rameezrajas | Shell Programming and Scripting | 8 | 07-31-2008 08:39 AM |
| Removing Blank Lines | dhanamurthy | Shell Programming and Scripting | 3 | 05-08-2008 01:52 AM |
|
|