Sponsored Content
Top Forums Shell Programming and Scripting Deleting lines ending with . from a file Post 302322556 by shekhar_v4 on Thursday 4th of June 2009 04:55:00 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
FILE(3) 								 1								   FILE(3)

file - Reads entire file into an array

SYNOPSIS
array file (string $filename, [int $flags], [resource $context]) DESCRIPTION
Reads an entire file into an array. Note You can use file_get_contents(3) to return the contents of a file as a string. PARAMETERS
o $filename - Path to the file. Tip A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen(3) for more details on how to specify the filename. See the "Supported Protocols and Wrappers" for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. o $flags - The optional parameter $flags can be one, or more, of the following constants: o FILE_USE_INCLUDE_PATH - Search for the file in the include_path. o FILE_IGNORE_NEW_LINES - Do not add newline at the end of each array element o FILE_SKIP_EMPTY_LINES - Skip empty lines o $context - A context resource created with the stream_context_create(3) function. Note Context support was added with PHP 5.0.0. For a description of contexts, refer to "Streams". RETURN VALUES
Returns the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached. Upon failure, file(3) returns FALSE. Note Each line in the resulting array will include the line ending, unless FILE_IGNORE_NEW_LINES is used, so you still need to use rtrim(3) if you do not want the line ending present. Note If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem. CHANGELOG
+--------+----------------------------+ |Version | | | | | | | Description | | | | +--------+----------------------------+ | 4.3.0 | | | | | | | file(3) became binary safe | | | | +--------+----------------------------+ EXAMPLES
Example #1 file(3) example <?php // Get a file into an array. In this example we'll go through HTTP to get // the HTML source of a URL. $lines = file('http://www.example.com/'); // Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num => $line) { echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br /> "; } // Another example, let's get a web page into a string. See also file_get_contents(). $html = implode('', file('http://www.example.com/')); // Using the optional flags parameter since PHP 5 $trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); ?> NOTES
Warning When using SSL, Microsoft IIS will violate the protocol by closing the connection without sending a close_notify indicator. PHP will report this as "SSL: Fatal Protocol Error" when you reach the end of the data. To work around this, the value of error_reporting should be lowered to a level that does not include warnings. PHP can detect buggy IIS server software when you open the stream using the https:// wrapper and will suppress the warning. When using fsockopen(3) to create an ssl:// socket, the developer is responsible for detecting and suppressing this warning. SEE ALSO
readfile(3), fopen(3), fsockopen(3), popen(3), file_get_contents(3), include(3), stream_context_create(3). PHP Documentation Group FILE(3)
All times are GMT -4. The time now is 02:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy