LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-24-2008, 10:24 PM   #1
docaia
LQ Newbie
 
Registered: Jan 2008
Posts: 18

Rep: Reputation: 0
Delete specific lines of a file beginning with a certain letter


I mistakenly attached a wrong header file to a data file, the header is so long but every line of the header begins with the letter "H", every other line begins with "S".

I need a script (or a command) that allows me to delete the header lines from the files instead of deleting them manually using the vi editor.

Please i need it to be briefly explained because i may use it to fix other files with other properties.
thank you
 
Old 08-24-2008, 10:28 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
I'm confused. How can EVERY line begin with H, but also EVERY OTHER line begin with S ?

Please show a couple of sample lines.

Last edited by Mr. C.; 08-24-2008 at 10:46 PM.
 
Old 08-24-2008, 10:44 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Semantics probably - I read it as "either".
Headers have "H", all others have "S".
 
Old 08-24-2008, 10:50 PM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Ah, "every other" means "all other".

Well, then, Mr. C. said, in said case, sed is our friend:

sed '/^H/d' input.file
 
Old 08-24-2008, 11:04 PM   #5
docaia
LQ Newbie
 
Registered: Jan 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Every line of the "header" begins with H, the other lines begin with S, here is a small part of the file:
Quote:
H26
H26 Record Specification
H26
H26 Item Definition of Field Start Stop
H26 ---- -------------------- ----- -----
H26 1 Record Identifier 1 - 1
H26 2 (Line) 2 - 17
H26 3 (Point) 18 - 25
H26 4 (Index) 26 - 26
H26 5 Source Type (Point Code) 27 - 28
H26 6 Station Depth 33 - 36
H26 7 Easting (X) 47 - 55
H26 8 Northing (Y) 56 - 65
H26 9 Surface Elevation 66 - 71
H26 10 Acquired Date/Time(Date) 72 - 74
H26 11 Acquired Date/Time(Time) 75 - 80
H26
H26 11111111112222222222333333333344444444445555555555666666666677777777778
H26 5678901234567890123456789012345678901234567890123456789012345678901234567890
S990 49962V1 0 817875.1 205975.0 -6.9222183629
S995 49962V1 0 817877.3 206225.9 -6.0222183702
S990 49952V1 0 817825.8 205974.9 -8.6222183733
S995 49952V1 0 817826.3 206225.9 -8.6222183759
S990 49942V1 0 817775.8 205975.3 -10.0222183822
S995 49942V1 0 817775.0 206225.0 -10.2222183845
S990 49932V1 0 817725.9 205974.9 -10.8222183909
S995 49932V1 0 817726.8 206225.0 -11.2222183932
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete specific Range of lines Using sed , awk, grep etc. joyds219 Linux - Newbie 4 03-28-2008 08:59 AM
printer printing vertical lines at beginning and end of lines makhand Linux - Hardware 0 09-02-2005 02:03 PM
vi command to find and delete all lines beginning with a character geomatt Linux - Software 8 12-20-2004 03:30 AM
How to delete a file beginning with '-'? zoomzoom Linux - General 2 02-02-2004 10:01 AM
delete some lines from a file freelinuxcpp Linux - Software 4 01-17-2004 10:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration