nixCraft Linux Forum

nixCraft

Linux / UNIX 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

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-07-2008, 11:43 PM
Junior Member
User
 
Join Date: Nov 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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
  #2 (permalink)  
Old 09-07-2008, 07:14 PM
rockdalinux's Avatar
Is that all you got?
User
 
Join Date: May 2005
Location: Planet Vegeta
OS: Redhat
Posts: 705
Thanks: 15
Thanked 19 Times in 18 Posts
Rep Power: 10
rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light
Default

Try sed
Code:
sed '/.:$/d' /path/to/file
sed '/.:$/d' /path/to/input > /path/to/output
cat  /path/to/output
__________________
Rocky Jr.
What's wrong? I hope I am not making you uncomfortable...

Never send a boy to do a mans job.
Reply With Quote
Reply


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 Off


Similar Threads

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


All times are GMT +5.5. The time now is 02:09 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

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 37 38