Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Want to remove all lines but not latest 50 lines from a file Post 302868267 by drl on Saturday 26th of October 2013 07:25:35 PM
Old 10-26-2013
Hi, Scrutinizer.

I don't recall if I had the intention of omitting spaces, but, yes, that's how it works. I may need to add an additional function to handle both. I'll think on that.

The templates I have for setting up the environment, displaying input, posting output, and sometimes doing the comparison now runs into the 50s. Although they are under version control, it can be a pain updating those that are related and have common code. My goal is to encourage the user to actually copy and paste the scripts, possibly staging the data files, running the code, and seeing if it matches my results. That also keeps me honest.

Thanks for the feedback ... cheers, drl
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remove lines from file

file: 1 xxxxxxx 2 xxx xxx 5 xxx xxx ... 180 xxxxxx 200 xxx how to remove any lines with the first number range 1-180 (9 Replies)
Discussion started by: bluemoon1
9 Replies

2. Shell Programming and Scripting

To remove the lines in my file

Hi, There seems to some hack attempts in my site. I have attached the index page of my site and I need to remove the below lines from the index page. The below lines are at the center of the file. --> </style> <script>E V A L( unescape(... (5 Replies)
Discussion started by: gsiva
5 Replies

3. UNIX for Dummies Questions & Answers

vi to remove lines in file

All, I have a text file with several entries like below: personname personname.domain.com I know there is a way to use vi to remove only the personname.domain.com line. Can someone help? I believe that it involves /s/g/ something...I just can't remember the exact syntax. Thanks (2 Replies)
Discussion started by: kjbaumann
2 Replies

4. Shell Programming and Scripting

remove lines from file

Hi gurus, i'm trying to remove a number of lines from a large file using the following command: sed '1,5000d' oldfile > newfile Somehow the lines in the old file are not deleted... Am I doing this wrongly? Any suggestions? :confused: Thanks! :) wee (10 Replies)
Discussion started by: lweegp
10 Replies

5. Shell Programming and Scripting

remove : lines from file

A small question I have a test.txt file I have contents as: a:google b:yahoo : c:facebook : d:hotmail How do I remove the line with : my output should be a:google b:yahoo c:facebook d:hotmail (5 Replies)
Discussion started by: aronmelon
5 Replies

6. Shell Programming and Scripting

remove blank lines and merge lines in shell

Hi, I'm not a expert in shell programming, so i've come here to take help from u gurus. I'm trying to tailor a csv file that i got to make it work for the LOAD FROM command. I've a datatable csv of the below format - --in file format xx,xx,xx ,xx , , , , ,,xx, xxxx,, ,, xxx,... (11 Replies)
Discussion started by: dvah
11 Replies

7. Shell Programming and Scripting

Remove lines from file

Hey Gang- I have a list of servers. I want to exclude servers that begin with and end with certain characters. Is there an easy command to do this? Example wvm1234dev wvm1234pro uvm1122dev uvm1122bku uvm1344dev I want to exclude any lines that start with "wvm" OR "uvm" AND end... (7 Replies)
Discussion started by: idiotboy
7 Replies

8. Shell Programming and Scripting

Two files, remove lines from second based on lines in first

I have two files, a keepout.txt and a database.csv. They're unsorted, but could be sorted. keepout: user1 buser3 anuser19 notheruser27 database: user1,2343,"information about",field,blah,34 user2,4231,"mo info",etc,stuff,43 notheruser27,4344,"hiya",thing,more thing,423... (4 Replies)
Discussion started by: esoffron
4 Replies

9. Shell Programming and Scripting

Remove lines that are subsets of other lines in File

Hello everyone, Although it seems easy, I've been stuck with this problem for a moment now and I can't figure out a way to get it done. My problem is the following: I have a file where each line is a sequence of IP addresses, example : 10.0.0.1 10.0.0.2 10.0.0.5 10.0.0.1 10.0.0.2... (5 Replies)
Discussion started by: MisterJellyBean
5 Replies

10. Shell Programming and Scripting

awk to remove lines that do not start with digit and combine line or lines

I have been searching and trying to come up with an awk that will perform the following on a converted text file (original is a pdf). 1. Since the first two lines are (begin with) text they are removed 2. if $1 is a number then all text is merged (combined) into one line until the next... (3 Replies)
Discussion started by: cmccabe
3 Replies
Taint::Runtime(3)					User Contributed Perl Documentation					 Taint::Runtime(3)

NAME
Taint::Runtime - Runtime enable taint checking SYNOPSIS
### sample "enable" usage #!/usr/bin/perl -w use Taint::Runtime qw(enable taint_env); taint_env(); # having the keyword enable in the import list starts taint ### sample $TAINT usage #!/usr/bin/perl -w use Taint::Runtime qw($TAINT taint_env); $TAINT = 1; taint_env(); # taint is now enabled if (1) { local $TAINT = 0; # do something we trust } # back to an untrustwory area ### sample functional usage #!/usr/bin/perl -w use strict; use Taint::Runtime qw(taint_start is_tainted taint_env taint untaint taint_enabled); ### other operations here taint_start(); # taint should become active taint_env(); # %ENV was previously untainted print taint_enabled() ? "enabled " : "not enabled "; my $var = taint("some string"); print is_tainted($var) ? "tainted " : "not tainted "; $var = untaint($var); # OR untaint $var; print is_tainted($var) ? "tainted " : "not tainted "; DESCRIPTION
First - you probably shouldn't use this module to control taint. You should probably use the -T switch on the commandline instead. There are a somewhat limited number of legitimate use cases where you should use this module instead of the -T switch. Unless you have a specific and good reason for not using the -T option, you should use the -T option. Taint is a good thing. However, few people (that I work with or talk to or discuss items with) use taint even though they should. The goal of this module isn't to use taint less, but to actually encourage its use more. This module aims to make using taint as painless as possible (This can be an argument against it - often implementation of security implies pain - so taking away pain might lessen security - sort of). In general - the more secure your script needs to be - the earlier on in your program that tainting should be enabled. For most setuid scripts, you should enable taint by using the -T switch. Without doing so you allow for a non-root user to override @INC which allows for them to put their own module in the place of trusted modules. This is bad. This is very bad. Use the -T switch. There are some common places where this module may be useful, and where most people don't use it. One such place is in a web server. The -T switch removes PERL5LIB and PERLLIB and '.' from @INC (or remove them before they can be added). This makes sense under setuid. The use of the -T switch in a CGI environment may cause a bit of a headache. For new development, CGI scripts it may be possible to use the -T switch and for mod_perl environments there is the PerlTaint variable. Both of these methods will enable taint and from that point on development should be done with taint. However, many (possibly most) perl web server implentations add their own paths to the PERL5LIB. All CGI's and mod_perl scripts can then have access. Using the -T switch throws a wrench into the works as suddenly PERL5LIB disappears (mod_perl can easily have the extra directories added again using <perl>push @INC, '/our/lib/dir';</perl>). The company I work for has 200 plus user visible scripts mixed with some mod_perl. Currently none of the scripts use taint. We would like for them all to, but it is not feasible to make the change all at once. Taint::Runtime allows for moving legacy scripts over one at a time. Again, if you are using setuid - don't use this script. If you are not using setuid and have reasons not to use the -T and are using this module, make sure that taint is enabled before processing any user data. Also remember that BECAUSE THE -T SWITCH WAS NOT USED %ENV IS INITIALLY NOT MARKED AS TAINTED. Call taint_env() to mark it as tainted (especially important in CGI scripts which all read from $ENV{'QUERY_STRING'}). If you are not using the -T switch, you most likely should use the following at the very top of your script: #!/usr/bin/perl -w use strict; use Taint::Runtime qw(enable taint_env); taint_env(); Though this module allows for you to turn taint off - you probably shouldn't. This module is more for you to turn taint on - and once it is on it probably ought to stay on. NON-EXPORTABLE XS FUNCTIONS The following very basic functions provide the base functionality. _taint_start() Sets PL_tainting _taint_stop() Sets PL_tainting _taint_enabled() View of PL_tainting _tainted() Returns a zero length tainted string. $TAINT VARIABLE The variable $TAINT is tied to the current state of taint. If $TAINT is set to 0 taint mode is off. When it is set to 1 taint mode is enabled. if (1) { local $TAINT = 1; # taint is enabled } EXPORT FUNCTIONS
enable/disable Not really functions. If these keywords are in the import list, taint will be either enabled or disabled. taint_start Start taint mode. $TAINT will equal 1. taint_stop Stop taint mode. $TAINT will equal 0. taint_env Convenience function that taints the keys and values of %ENV. If the -T switch was not used - you most likely should call this as soon as taint mode is enabled. taint Taints the passed in variable. Only works on writeable scalar values. If a scalar ref is passed in - it is modified. If a scalar is passed in (non ref) it is copied, modified and returned. If a value was undefined, it becomes a zero length defined and tainted string. taint($var_to_be_tainted); my $tainted_copy = taint($some_var); For a stronger taint, see the Taint module by Dan Sulgalski which is capable of tainting most types of data. untaint Untaints the passed in variable. Only works on writeable scalar values. If a scalar ref is passed in - it is modified. If a scalar is passed in (non ref) it is copied, modified and returned. If a value was undefined it becomes an untainted undefined value. Note: Just because the variable is untainted, doesn't mean that it is safe. You really should use CGI::Ex::Validate, or Data::FormValidator or any of the Untaint:: modules. If you are doing your own validation, and once you have put the user data through very strict checks, then you can use untaint. if ($var_to_be_untainted =~ /^[w.-]{0,100}$/) { untaint($var_to_be_untainted); } my $untainted_copy = untaint($some_var); taint_enabled Boolean - Is taint on. tainted Returns a zero length tainted string. is_tainted Boolean - True if the passed value is tainted. taint_deeply Convenience function that attempts to deply recurse a structure and mark it as tainted. Takes a hashref, arrayref, scalar ref, or scalar and recursively untaints the structure. For a stronger taint, see the Taint module by Dan Sulgalski which is capable of tainting most types of data. TURNING TAINT ON
(Be sure to call taint_env() after turning taint on the first time) #!/usr/bin/perl -T use Taint::Runtime qw(enable); # this does not create a function called enable - just starts taint use Taint::Runtime qw($TAINT); $TAINT = 1; use Taint::Runtime qw(taint_start); taint_start; TURNING TAINT OFF
use Taint::Runtime qw(disable); # this does not create a function called disable - just stops taint use Taint::Runtime qw($TAINT); $TAINT = 0; use Taint::Runtime qw(taint_stop); taint_stop; CREDITS
C code was provided by "hv" on perlmonks. This module wouldn't really be possible without insight into the internals that "hv" provided. His post with the code was shown in this node on perlmonks: http://perlmonks.org/?node_id=434086 The basic premise in that node was the following code: use Inline C => 'void _start_taint() { PL_tainting = 1; }'; use Inline C => 'SV* _tainted() { PL_tainted = 1; return newSVpvn("", 0); }'; In this module, these two lines have instead been turned into XS for runtime speed (and so you won't need Inline and Parse::RecDescent). Note: even though "hv" provided the base code example, that doesn't mean that he necessarily endorses the idea. If there are disagreements, quirks, annoyances or any other negative side effects with this module - blame me - not "hv." THANKS
Thanks to Alexey A. Kiritchun for pointing out untaint failure on multiline strings. AUTHOR
Paul Seamons (2005) C stub functions by "hv" on perlmonks.org LICENSE
This module may be used and distributed under the same terms as Perl itself. perl v5.16.3 2007-06-14 Taint::Runtime(3)
All times are GMT -4. The time now is 07:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy