Sponsored Content
Full Discussion: Insert line into file
Top Forums Shell Programming and Scripting Insert line into file Post 302210406 by vinay123 on Tuesday 1st of July 2008 12:54:59 AM
Old 07-01-2008
Insert line into file

Hi,

My File 'temp.txt' contents are like this.

<Managers>
Mng={{FIL|FAVEI.mng|111}|15.000000|17.000000|17.000000|
Mng={{FIL|FAPSV.mng|222}|3.000000|0.000000|0.000000|0.000000|
Mng={{FIL|FAVIF.mng|333}|8.000000|8.000000|8.000000|8.000000|
Mng={{FIL|FAVGR.mng|444}|15.000000|15.000000|15.000000|
Mng={{FIL|FAPST.mng|555}|3.000000|3.000000|3.000000|3.000000|
Mng={{FIL|FAVGO.mng|666}|13.000000|14.000000|14.000000|14.000000|
Mng={{FIL|FASOT.mng|777}|5.000000|5.000000|5.000000|5.000000}
Mng={{FIL|FAWSC.mng|888}|4.000000|4.000000|4.000000|4.000000}
</Managers>

Here I want to insert the line similar to other lines before </Managers> with
exactly similar number of columns. For example,

Mng={{FIL|FAPSA.mng|123}|0.000000|0.000000|0.000000|0.000000}

nedds to be inserted using perl script.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Insert a line as the first line into a very huge file

Hello, I need to insert a line (like a header) as the first line of a very huge file (about 3 ml rows). I am able to do it with sed, but redirecting the output and creating a new file takes quite some time. I was wondering if there was a more efficient way of doing it? Any help would be... (3 Replies)
Discussion started by: shriek
3 Replies

2. Shell Programming and Scripting

insert a line in a file

Hello guys, Need to know how to insert a line at top of the file, without using temp files. Can we do it on the fly? Regards, Rishi (7 Replies)
Discussion started by: RishiPahuja
7 Replies

3. UNIX for Advanced & Expert Users

help with insert line into file

hi..i wanted to know is there any way to take input from the user and copy that a particular line number in a particular file for eg . i wanted to create acl in squid at line number 2400 in squid.conf file so the user gives an input like acl inetblock src 192.168.0.0/255.255.0.0 so is there... (4 Replies)
Discussion started by: tarunicon
4 Replies

4. Shell Programming and Scripting

How to insert Parentheses to each line in a file

Hi I have a file with numbers like this : 123 456 6798 9073233 12 8644 Now, I need to insert parentheses to each and every line like below : (123) (456) (6798) (9073233) (12) (8644) can anyone tell me a solution? (8 Replies)
Discussion started by: sudharsan23
8 Replies

5. Shell Programming and Scripting

Insert blank line in a file

I have a file with data as below : Heading 1 ------------- Heading 1 data1 Heading 1 data2 Heading 1 data3 Heading 1 data4 Heading 2 ------------- Heading 2 data1 Heading 2 data2 Heading 2 data3 Heading 2 data4 Heading 3 ------------- Heading 3 data1 Heading 3 data2 Heading 3... (2 Replies)
Discussion started by: yoursdivu
2 Replies

6. Programming

insert line into a file

how to insert a line of text that is next to the current line(file pointer pointing to) in the file ?? :wall: ex: suppose a file named 'Sample' has the following content in it. this is to give clear idea about the problem if file pointer is pointing to the first line then i want to... (3 Replies)
Discussion started by: kavitha rao
3 Replies

7. Shell Programming and Scripting

Insert a new line before every 5th line in a file

Hi, I need to insert a new line containing the string "QUERY" above every 5 lines. The below piece of code inserts a new line after every 5th line awk '{print $0} !(NR%5) {print "QUERY"}' sed 'n;n;n;n;G;' --> I do not know how to give "QUERY" string here But I need to insert it before... (4 Replies)
Discussion started by: royalibrahim
4 Replies

8. Shell Programming and Scripting

Insert a line in a file by deleting that line from another file

Hi all, I have a huge file(size more that 5GB). I want to do some manupulation with the records and write to another file. As the size of the file is huge and there is a space constraint in that directory, I want to delete that record from first file after writing it in to second file.... (3 Replies)
Discussion started by: gani_85
3 Replies

9. Shell Programming and Scripting

How to read a text file line by line and insert into a database table?

I have a test file that I want to read and insert only certain lines into the the table based on a filter. 1. Rread the log file 12 Hours back Getdate() -12 Hours 2. Extract the following information on for lines that say "DUMP is complete" A. Date B. Database Name C.... (2 Replies)
Discussion started by: JolietJake
2 Replies

10. UNIX for Beginners Questions & Answers

Insert a line of text on nth line of a file

Hi All, I am using UNix Sun OS sun4u sparc SUNW,SPARC-Enterprise My intention is to insert a line of text after 13th line of every file inside a particular directory. While trying to do it for a single file , i am using sed sed '3 i this is the 4th line' filename sed: command garbled: 3... (5 Replies)
Discussion started by: gotamp
5 Replies
Regexp::List(3pm)					User Contributed Perl Documentation					 Regexp::List(3pm)

NAME
Regexp::List - builds regular expressions out of a list of words SYNOPSIS
use Regexp::List; my $l = Regexp::List->new; my $re = $l->list2re(qw/foobar fooxar foozap fooza/); # $re is now qr/foo(?:[bx]ar|zap?)/ ABSTRACT
This module offers "list2re" method that turns a list of words into an optimized regular expression which matches all words therein. The optimized regular expression is much more efficient than a simple-minded '|'-concatenation thereof. DESCRIPTION
This module use Object-Oriented approach so you can use this module as a base and tweak its features. This module is a base class of Regexp::Optimizer. EXPORT Since this is an OO module there is no symbol exported. METHODS
This module offers methods below; $l = Regexp::List->new(key=>value, ...) Constructor. When arguments are fed in key => value, manner, it sets attributes. See "$l->set" for details $re = $l->list2re(list of words ...) Does the job. Takes a list of words and turn it into an optimal regular expresson. See "IMPLEMENTATION" to find out how it is achieved. If you want to know the underlying black magic even further, see the source. $l->set(key => value, ...) Sets attributes. There are many attributes supported but let me mention just a few that you may be interested. lookahead Whether you prepend a lookahead assertion or not. Default value is 1. This module is smart enough to omit the assertion when you don't need one. $re = $l->list2re(qw/1 2 3 infinity/); # qr/(?=[123i])(?:[123]|infinity)/ $re = $l->set(lookahead=>0)->list2re(qw/1 2 3 infinity/); # qr/(?:[123]|infinity)/ quotemeta Whether you quote metacharacters or not. Default is 1. If you really need this feature try Regexp::Optimizer instead. @list = qw/3 3.14 3.14159265358979/; $re = $l->list2re(@list); # qr/3(?:.14(?:159265358979)?)?)/ $re = $l->set(lookahead=>0)->list2re(@list); # qr/3(?:.14(?:159265358979)?)?)/ # which does match 3.14 but also "11+3=14" modifies Currently it accepts 'i', 'm', 's', and 'x', the same as regular expression modifiers. @list = qw/Perl perl BASIC basic/; $re = $l->list2re(@list); # qr/(?=[BPbp])(?:[Pp]erl|BASIC|basic)/ $re = $l->set(modifiers => 'i')->list2re(@list); # qr/(?=[bp])(?:perl|basic)/i print $l->set(modifiers => 'x')->list2re(@list); # Try for yourself; Isn't itcute ? $l->expand($re); Utility methods to expand a regular expression. Handy when you want to check the complex regexes. $l->unexpand($re); Utility methods to unexpand a regular expression. IMPLEMENTATION
This module optimizes the regular expression as follows. Let's see what happens when qw/foobar fooxar foozap fooza/ is fed trie building (common prefix aggregation) first the corresponding trie structure is built +- bar foo -+- xar +- za -+- p +- '' common suffix aggregation it checks if any leaf node can be optimized for common suffix. In this case we can do so to "bar" and "xar". +- b -+-ar foo -+- x -+ +- za -+- p +- '' character class conversion If a branch contains more than two single characters, it turns it into a character class. foo -+- [bx] --- ar +- za -+-p +- '' empty leaf to "?" Empty leaf is converted to a '?' quantifier foo -+- [bx] --- ar +- za -+-p? join all leafs into a group And the final result is reached. foo(?:[bx]ar|zap?) BENCHMARKS
This module is faily robust. You can practically use this module to find a regular expression that matches all words in a dictionary. Here is a result by on perl 5.8.0, FreeBSD 4-Stable, Pentium III 800 Mhz with 512 MB RAM. # Sat May 31 09:11:06 2003 ( 0.000000 s) Reading /usr/share/dict/words # Sat May 31 09:11:07 2003 ( 0.847797 s) 235881 lines read. # Sat May 31 09:11:07 2003 ( 0.000000 s) Making regexp. # Sat May 31 09:13:09 2003 ( 121.596928 s) Done. # Sat May 31 09:13:09 2003 ( 0.000000 s) Saving to t/words.rx # Sat May 31 09:13:09 2003 ( 0.000000 s) Reading t/words.rx # Sat May 31 09:13:13 2003 ( 3.679176 s) Done. # Sat May 31 09:13:13 2003 ( 0.000000 s) Opening /usr/share/dict/words for comparison. # Sat May 31 09:13:13 2003 ( 0.255222 s) /usr/share/dict/words:235881 lines found. # Sat May 31 09:13:13 2003 ( 0.000000 s) Showtime! # 235881/235881 # Sat May 31 10:44:17 2003 ( 5464.370409 s) Done. # Sat May 31 10:44:17 2003 ( 5464.370624 s) 43.167 matches/s The result of optimization is obvious as the number of alteration increases. Here is a result of a benchmark which matches randomly picked words against "/usr/share/dict/words". ==== 2 words Rate naive optim naive 1.79/s -- -28% optim 2.49/s 39% -- ==== 256 words s/iter naive optim naive 31.7 -- -81% optim 5.95 433% -- SEE ALSO
Regexp::Optimizer -- uses this module as its base "eg/" directory in this package contains example scripts. Perl standard documents perltodo, perlre CPAN Modules Regexp::Presuf, Text::Trie Books Mastering Regular Expressions <http://www.oreilly.com/catalog/regex2/> AUTHOR
Dan Kogai <dankogai@dan.co.jp> COPYRIGHT AND LICENSE
Copyright 2003 by Dan Kogai, All Rights Reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2011-11-16 Regexp::List(3pm)
All times are GMT -4. The time now is 01:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy