nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

How to delete only certain lines

This is a discussion on How to delete only certain lines within the Shell scripting forums, part of the Development/Scripting category; I have a file where a short line with one field (e.g. Mcol2208 is followed either by one or more ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-07-2008, 11:43 PM
Junior Member
User
 
Join Date: Nov 2006
Posts: 4
Rep Power: 0
mike herdman
Default How to delete only certain lines

I have a file where a short line with one field (e.g. Mcol2208 is followed either by one or more lines with 12 fields or by another short line. I need to delete those short lines that are not followed by a longer one (i.e. Mcol2210: and Mcol3898: in the example below). How can this be done in a shell script?

Mcol2208:
51 202_927 Mcol2208 Mcol3898 0.0003 3.91e-03 202 927 726 388 2 26
146 582_1040 Mcol2208 Mcol_DAI 0.0172 3.07e-02 582 1040 459 224 8 82
Mcol2210:
Mcol3898:
Mcol474:
3 1_530 PhoG2-68 Mcol474 0.0023 1.84e-02 1 530 530 299 1 24
31 135_678 Mcol474 Pho_3590 0.0136 4.67e-02 135 678 544 315 2 25
32 135_703 PhoI1-5 Mcol474 0.0000 1.13e-03 135 703 569 326 0 25
Mcol475:
11 48_503 Mcol475 PhoV52 0.0476 1.35e-01 48 503 456 260 0 13

Help will be greatly appreciated.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-09-2008, 07:14 PM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 557
Rep Power: 6
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

Try sed
Code:
sed '/.:$/d' /path/to/file
sed '/.:$/d' /path/to/input > /path/to/output
cat  /path/to/output
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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

Similar Threads

Thread Thread Starter Forum Replies Last Post
Shell Delete Directory chimu Slackware 2 05-31-2008 03:36 PM
How to print some lines from a file Prahlad Shell scripting 3 04-23-2008 11:25 PM
Script to display number of lines and words from a file newbewie Shell scripting 2 12-07-2007 10:37 PM
Calculations across different lines & columns of a file Guest Shell scripting 2 09-16-2005 04:18 AM
using sed to delete everything except needed patterns guest Shell scripting 8 09-12-2005 02:57 AM


All times are GMT +5.5. The time now is 12:06 PM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36