The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Grep and delete lines except the lines with strings vj8436 Shell Programming and Scripting 14 04-17-2009 11:25 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
sed help - delete last 2 lines. vino Shell Programming and Scripting 2 06-08-2005 06:50 AM
delete blank lines or lines with spaces only vascobrito UNIX for Dummies Questions & Answers 3 01-13-2004 07:36 AM
delete lines.. alisevA3 UNIX Desktop for Dummies Questions & Answers 8 05-29-2002 08:33 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-02-2009
mrpranab mrpranab is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 4
how to delete lines

Hi All,

I have a file called test.flg.fl and the data contains in the file as below

mmddyy_list20.prn
mmddyy_list21.prn
mmddyy_list22.prn
mmddyy_list23.prn
mmddyy_list24.prn
mmddyy_list25.prn
mmddyy_list26.prn
mmddyy_list27.prn
mmddyy_list28.prn
mmddyy_list29.prn
mmddyy_list3.prn
mmddyy_list30.prn
mmddyy_list31.prn
mmddyy_list32.prn
mmddyy_list33.prn
mmddyy_list34.prn
mmddyy_list35.prn
mmddyy_list36.prn
mmddyy_list37.prn
mmddyy_list38.prn
mmddyy_list42.prn

I need to delete lines which contain list21 to list 37 (i.e. list21, list22, list23 etc etc..). So my new file test.flg.fl will be now looks like below after I delete the lines.

mmddyy_list20.prn
mmddyy_list3.prn
mmddyy_list38.prn
mmddyy_list42.prn

Can you please tell me the command how to do this to delete those lines using Unix shell scripts? Please let me know if you need more informations.

Thank you!
  #2 (permalink)  
Old 01-02-2009
nj78 nj78 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 103
If you are familiar with egrep and regular expressions, then just cat the file and pipe to egrep -v to remove what you don't need. Good exercise to learn this, plenty of material to find using google.
  #3 (permalink)  
Old 01-02-2009
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,190
Code:
awk -F '[t.]' ' $2 < 21 || $2 > 37' test.flg.fl
  #4 (permalink)  
Old 01-02-2009
cfajohnson's Avatar
cfajohnson cfajohnson is online now Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,315
Quote:
Originally Posted by nj78 View Post
If you are familiar with egrep and regular expressions, then just cat the file and pipe to egrep -v to remove what you don't need. Good exercise to learn this, plenty of material to find using google.

Don't cat the file. Use the filename as the final argument to grep.

However, for this exercise, awk is better:

Code:
awk -F '_list' '
 { num = $2; sub( /.prn/, "", num ); num = num + 0 }
 num < 21 || num > 37
' "$FILE"
Sponsored Links
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 07:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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