Deleting lines ending with . from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting lines ending with . from a file
# 1  
Old 06-04-2009
Deleting lines ending with . from a file

HI

I'm looking to delete lines ending with .tk from below data file
---------
abc.tk
mgm.tk
dtk
mgmstk
------

I have written below code
----
sed '/.tk *$/d' dat_file.txt > temp.txt
----

But its deleting all the lines ending with tk. I need to delete only the lines ending .tk

my expected output is
----
dtk
mgmstk
----

Can you please help me to resolve the issue?

Thanks.
Shekhar
# 2  
Old 06-04-2009
if you have Python, here's an alternative
Code:
#!/usr/bin/evn python
import fileinput
for line in fileinput.FileInput("file",inplace=1):
    line=line.strip()
    if not line.endswith(".tk"):
        print line

output
Code:
# more file
abc.tk
mgm.tk
dtk
mgmstk
# ./test.py
# more file
dtk
mgmstk

# 3  
Old 06-04-2009
Can you give the code using sed
# 4  
Old 06-04-2009
use this

Code:
 sed '/\.tk *$/d' dat_file.txt > temp.txt

you need to replace the . with \. in order to remove its special usage.
# 5  
Old 06-04-2009
Thanks shubhendu. ur code working pefectly
# 6  
Old 06-05-2009
Code:
sed '/\..*$/d' yourfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove certain lines from file based on start of line except beginning and ending

Hi, I have multiple large files which consist of the below format: I am trying to write an awk or sed script to remove all occurrences of the 00 record except the first and remove all of the 80 records except the last one. Any help would be greatly appreciated. (10 Replies)
Discussion started by: nwalsh88
10 Replies

2. UNIX for Dummies Questions & Answers

Deleting last 3 lines from a file via sed

Hi Anybody can help me to delete the last 3 lines from a text file via sed under SunOS 5.8? Thanks Aldar (4 Replies)
Discussion started by: aldar
4 Replies

3. Shell Programming and Scripting

deleting specific lines in a file

I want to delete all lines from a file (orig_file) that contain the regex values (bad_inv_list) I tried a for each loop with sed but it isn't working for file in `cat bad_inv_list`; do sed '/$file/d' orig_file > pared_down_file.1 mv pared_down_file.1 orig_file done I've added... (2 Replies)
Discussion started by: verge
2 Replies

4. Shell Programming and Scripting

Deleting certain new lines from a file with shell

Good morning!!! Im a newbie with shell programing and i was wondering if there is a way to delete certain new lines from a file, here is an example of my current file: >seq_0 GTGAGATTGCTAATGAGCTGCTTTTAGGGGGCGTGTTGTGCTTGCTTTCC AACTTTTCTAGATTGATTCTACGCTGCCTCCAGCAGCCACCCCTCCCATC... (11 Replies)
Discussion started by: machalita
11 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. Solaris

removing particular lines ending with a .cnt extension in a text file

I have a text file with rows of information (it is basically a ls command information(o/p from ls command)) I need to remove the lines ending with a .cnt extension and keep the lines ending with .zip extension, how to accomplish this. I also only need the date,size and name of the file from every... (2 Replies)
Discussion started by: ramky79
2 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