The UNIX and Linux Forums  

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



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
deleting white spaces in a file mraghunandanan UNIX for Dummies Questions & Answers 2 05-26-2009 01:21 PM
csh script for deleting extra spaces in text file hertingm Shell Programming and Scripting 2 03-12-2009 04:22 PM
Deleting end line spaces for along file osymad Shell Programming and Scripting 3 02-23-2005 01:56 PM
deleting white spaces cary530 UNIX for Dummies Questions & Answers 10 02-17-2004 01:22 PM
delete blank lines or lines with spaces only vascobrito UNIX for Dummies Questions & Answers 3 01-13-2004 07:36 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 06-16-2009
skray skray is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 4
Deleting lines starting with spaces then non-numerals

I did a search but couldn't find a thread that seemed to answer this but my apologies if it has been answered before.

I have some text files and I need to remove any line that does not start with a number (0-9). In actuality every line like this starts with a 'T' (or 't') but there are a varying number of spaces from the start of the line to the first t.

Ex: ' Track 9, .....'
or
' t x y q.....'

Is there a sed or grep expression I can use to delete these lines?


Thanks in advance for any help.
  #2 (permalink)  
Old 06-16-2009
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink grep command

How about

Code:
grep "^[0-9]" infile > outfile

which will copy only lines that begin with a number in 0-9 range
  #3 (permalink)  
Old 06-16-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
sed '/^ *[^0-9]/d' myFile

  #4 (permalink)  
Old 06-16-2009
skray skray is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 4
Wow, thanks for the 2 quick responses.

I tried both and wound up with blank output files. Looking back at the original file, every numeric line has 2 spaces before the numbers start....is it possible to add that into the expression? I looked for how to represent a space in regular expressions but came up with 8 or 9 different syntax...

P.S. I don't think I've ever seen the true value of consistently formatted files but I sure do now.

P.P.S. Again thanks for the help.
  #5 (permalink)  
Old 06-16-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
sorry:

Code:
sed -n '/^ *[0-9]/p' myFile

  #6 (permalink)  
Old 06-16-2009
skray skray is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 4
Thanks! It even had the added benefit of skipping blank lines, you guys are great.
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:57 AM.


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