The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Special Forums > UNIX Desktop for Dummies Questions & Answers
.
google unix.com



UNIX Desktop for Dummies Questions & Answers Discuss UNIX and Linux user interfaces like GNOME, KDE, CDE, and Open Office here. All UNIX and Linux Newbies Welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Delete lines mohan705 UNIX for Advanced & Expert Users 2 04-04-2008 10:09 AM
How to delete first 5 lines and last five lines in all text files ragavendran31 Shell Programming and Scripting 10 02-21-2008 07:58 AM
delete some lines fongthai Shell Programming and Scripting 2 10-16-2007 11:54 PM
How to delete more lines kamathg Shell Programming and Scripting 1 10-05-2007 07:39 AM
delete blank lines or lines with spaces only vascobrito UNIX for Dummies Questions & Answers 3 01-13-2004 07:36 AM

Closed Thread
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 05-27-2002
alisevA3 alisevA3 is offline
Registered User
  
 

Join Date: May 2002
Posts: 33
Lightbulb delete lines..

hi All,

I have a file like this;

aaaaaaaaaa

bbbbbbbb

cccccc

ddddddddddd

........

xxxxxxxxxxxx

I want to delete hole lines and it must be like this

aaaaaaaaaa
bbbbbbbb
cccccc
ddddddddddd

how can I do this ??

R.

Alice
  #2 (permalink)  
Old 05-27-2002
hassan2 hassan2 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2002
Location: London, England
Posts: 262
Wink

Edit the file using vi editor then type in
dd on the empty space this will delete the line

the procedure is

vi filename
dd

then :wq to save
  #3 (permalink)  
Old 05-27-2002
alisevA3 alisevA3 is offline
Registered User
  
 

Join Date: May 2002
Posts: 33
Lightbulb delete lines

I have more than 1500 line and 30 files. if I use vi and "dd" I can complete until end of my life.
  #4 (permalink)  
Old 05-27-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,126
In order to automate this we will need a more clear definition of the problem. Your example seems to imply that you want to keep only the first four non-blank lines. Is this correct?
  #5 (permalink)  
Old 05-27-2002
alisevA3 alisevA3 is offline
Registered User
  
 

Join Date: May 2002
Posts: 33
Lightbulb

yes thats right.
this file is contaings 1530 lines and it has blank lines between each lines. I want to delete blank lines in this files.
  #6 (permalink)  
Old 05-27-2002
Kevin Pryke Kevin Pryke is offline
Registered User
  
 

Join Date: Feb 2002
Location: Bradford, UK
Posts: 70
You can use awk

awk '{if ( $1 != "") print $1}' < file.in > file.out

file.in is your input file name &
file.out is your output file name
  #7 (permalink)  
Old 05-28-2002
Kelam_Magnus's Avatar
Kelam_Magnus Kelam_Magnus is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
In the spirit of "many ways to do things in UNIX", Here goes.

cat file.in | grep -v ^$ > file.out

This will use the descriptors ^ for beginning of line and $ for end of line to match a blank line and remove from output with the -v option of grep.

Cool...

It may be less efficient than awk but still valid. And less syntax problems.

Closed Thread

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 08:52 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