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 > 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
how to remove the first line from a flat file ? xli UNIX for Dummies Questions & Answers 21 12-16-2008 01:37 AM
How to remove FIRST Line of huge text file on Solaris madoatz UNIX for Dummies Questions & Answers 5 06-23-2007 01:19 PM
How to remove last line of the file mani_um Shell Programming and Scripting 3 05-14-2007 08:35 AM
Remove header(first line) and trailer(last line) in ANY given file madhunk Shell Programming and Scripting 2 03-13-2006 03:36 PM
Remove every third line from a file bistru Shell Programming and Scripting 4 01-31-2006 07:26 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 04-10-2008
new2ss new2ss is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 133
remove a line within a file

Hi all, i have a text file similar to below
Code:
A1
A2
A3
B1 ... .... *** # first occurance
B1 ... .... *** # second occurance 
B1 ... .... *** # third occurance
My desired output is
Code:
B1 ... .... *** # second occurance
B1 ... .... *** # third occurance
I want to remove the first line that is after the A's.

I have a primitive method
Code:
 /cat myfile | grep B >> desired_file
I only managed to remove the lines beginning with A. What can i next do to remove the first line from the results of grep-ping B?
  #2 (permalink)  
Old 04-10-2008
divzz divzz is offline
Registered User
  
 

Join Date: Mar 2008
Location: Bangalore
Posts: 20
Smile

Hi,
Hoping that only fourth line has to be removed, try out the given code below.

sed -e '4s/B1//g' myfile |grep "B1"

Hope this solves your problem.
  #3 (permalink)  
Old 04-11-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Or 'grep B myfile | tail +1' to omit the first occurrence (which is spelled with two r:s and two e:s and no a)
  #4 (permalink)  
Old 11-23-2008
Magnet Magnet is offline
Registered User
  
 

Join Date: Dec 2005
Location: West coast
Posts: 1
Yet another alternative

You can also use csplit on the result of the grep-ped file

csplit (options) input-file-name 2

will produce two output files, one containing only the first record and the second file will contain the other stuff. Essentially you're splitting the file at line 2.

Use the options to specify a prefix and/or suffix if you want.

The files resulting from the csplit can be cat-ed together to recreate the file being split. Moreover, csplit leaves your input file intact.
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:11 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