Deleting lines in text file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting lines in text file
# 1  
Old 05-16-2008
Deleting lines in text file

Hi everyone,

I have text files that I want to delete lines from. I have searched through this forum for quite some time and found examples of both awk and sed. Unfortunately, I was not able to successfully do what I want. Well to some extent. I did manage to delete the first 15 lines from each of the text files, since all the text files will have the same first 15 lines.

So, I have a text file that looks like this:

Id First Name Last Name
--- ---------- ---------
1 Mary Jane
2 Joe Blowe

2 record(s) selected.

Return Status = 0


Notice the lines in bold....every text file will have this at the end. This file will be emailed and the recepients won't have a clue to what those two lines mean, so I would like to remove them. Any suggestions? THANKS!
# 2  
Old 05-16-2008
This should do the job:

Code:
awk '/record(s) selected.$/{exit}1' file

Regards
# 3  
Old 05-16-2008
Hmm..that did not seem to have any results...but thanks anyways. What I did is:

awk 'FNR>15' myfile |grep -v -e "record(s) selected." -e "Return Status" > mynewfile



Don't know if that is the wrong way of doing it. I am sure you experienced folks will have a better way of doing it, but alas, it accomplished what I wanted.

Thanks again!!
# 4  
Old 05-16-2008
Oops, forgot some quotes:

Code:
awk '/record\(s\) selected.$/{exit}1' file

Regards
# 5  
Old 05-16-2008
Awesome, it worked! Don't you just love it how a single slash can make a difference? Smilie
# 6  
Old 05-16-2008
Quote:
Originally Posted by hern14
Awesome, it worked! Don't you just love it how a single slash can make a difference? Smilie
Love it? It can drive you crazy sometimes...Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Deleting all the N lines after the line in which text is found.

Hi! I want to delete N (say 10) lines after the line which text is found in a file "A".Also to delete the line in which the text is found. Only one occurrence of the search string in the file "A" The text to be deleted is in another text file "B". All the search texts in the file "B" are in... (3 Replies)
Discussion started by: shahid1632
3 Replies

3. Shell Programming and Scripting

Deleting specific lines from text file via scripting

Hi, I'm trying to search for some number and from that line, i need to delete the 5th line exactly. Eg: Consider below as text file data: 10000 a b c d e . . . 10000 w q t (8 Replies)
Discussion started by: Gautham
8 Replies

4. UNIX for Dummies Questions & Answers

Deleting lines that contain a specific string from a space delimited text file?

Hi, I have a space delimited text file that looks like the following: 250 rs10000056 0.04 0.0888 4 189321617 250 rs10000062 0.05 0.0435 4 5254744 250 rs10000064 0.02 0.2403 4 127809621 250 rs10000068 0.01 NA 250 rs1000007 0.00 0.9531 2 237752054 250 rs10000081 0.03 0.1400 4 17348363... (5 Replies)
Discussion started by: evelibertine
5 Replies

5. Shell Programming and Scripting

deleting lines from file

We have a server that logs transactions to a file. I want to write a script that will delete the first 50 lines of the file daily without renameing the file or moving the file. (8 Replies)
Discussion started by: daveisme
8 Replies

6. UNIX for Advanced & Expert Users

Deleting lines from a file

How I can delete 100 lines anywhere in a file without opening a file and without renaming the file. (11 Replies)
Discussion started by: Nirgude07
11 Replies

7. UNIX for Dummies Questions & Answers

Deleting whole lines from a file

I have a file with 65 sets of 35 coordinates, and would like to isolate these coordinates so that I can easily copy the coordinates to another file. The problem is, I've got a 9 line header before each set of coordinates (so each set is 44 lines long). There are a zillion threads out there about... (3 Replies)
Discussion started by: red baron
3 Replies

8. Shell Programming and Scripting

deleting lines from multiple text files

I have a directory full of text data files. Unfortunately I need to get rid of the 7th and 8th line from them all so that I can input them into a GIS application. I've used an awk script to do one at a time but due to the sheer number of files I need some kind of loop mechanism to automate... (3 Replies)
Discussion started by: vrms
3 Replies

9. Shell Programming and Scripting

Deleting lines in a file

How do I delete all the lines after the line containing text ***DISCLOSURES*** . I want to delete this line too. Thank you (2 Replies)
Discussion started by: reachsamir
2 Replies

10. Shell Programming and Scripting

Deleting last 2 lines from the file.

Hi I have a file & always I need to remove or delete last 2 lines from that file. So in a file if I have 10 lines then it should return me first 8 lines. Can someone help me? (4 Replies)
Discussion started by: videsh77
4 Replies
Login or Register to Ask a Question