Sponsored Content
Full Discussion: Insert text at line number
Top Forums Shell Programming and Scripting Insert text at line number Post 302337751 by cfajohnson on Friday 24th of July 2009 10:20:51 PM
Old 07-24-2009
Quote:
Originally Posted by J-Man
I wrote a script to grep for a closing XML node. Then I need it to navigate up a line and insert some XML. Then go to the next occurrance.

Code:
insert="<xxx>XML to insert</xxx>"
awk -v insert="$insert" '
  /<\/whatever>/ { print insert }
                { print }
   ' FILENAME

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to insert a line number on every line

hi... i have a file with data and would like to insert a number and bracket 1) ...2) at the beginning of every successive line; to add some formatting to the text (3 Replies)
Discussion started by: mopimp
3 Replies

2. Shell Programming and Scripting

sed/awk to insert comment at defined line number

Hi there, may someone easily help me on this : I want to insert a text in a specific line number like : linenumb2start=`cat memory_map.dld | nl -ba | egrep -i "label" | cut -f1` line2insert=`expr $linenumb2start + 2` and now I need to replace something like {} with {comment} at... (8 Replies)
Discussion started by: homefp
8 Replies

3. Shell Programming and Scripting

How to insert some constant text at beginig of each line within a text file.

Dear Folks :), I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp. I can do this in vi editor by using this command :g/^/s//BBB_ e,g I have a file named as Test.dat and it containins below text: michal... (4 Replies)
Discussion started by: Muhammad Afzal
4 Replies

4. Shell Programming and Scripting

Insert output into file at line number

I need to insert the output of a script into a specific line number of a txt file. I've read the Sed man page and searched the forums and it's not immediately clear how I would go about doing this. (4 Replies)
Discussion started by: pluto7777
4 Replies

5. Shell Programming and Scripting

Insert new line based on numerical number of column

My input file: Class Number Position Range 1 Initial 50 1 Initial 50 2 Terminal 150 2 Terminal 20 2 Single 10 3 Single 20 4 Double 50 5 Initial 50 5 Initial 60 Class Number... (11 Replies)
Discussion started by: patrick87
11 Replies

6. Shell Programming and Scripting

Insert a variable to a text file after fixed number of lines

Hi, I am new to unix. I need to insert a variable which contains some lines of text into a text file after fixed number of lines.. Please help me on this.. Thanks in Advance, Amrutha (3 Replies)
Discussion started by: amr89
3 Replies

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

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

9. Shell Programming and Scripting

Insert text at the beginning of every even number line

i am trying to insert text at the beginning of every even number line with awk i can do it with odd number lines with this command awk 'NR%2{$0="some text "$0}1' filehow can i edit this command thanks (5 Replies)
Discussion started by: bob123
5 Replies

10. UNIX for Beginners Questions & Answers

Insert the line number from text file to filename output

Hi everyone :) I have a file "words.txt" containing hundreds of lines of text. Each line contains a slogan. Using the code below i am able to generate an image with the slogan text from each line. The image filename is saved matching the last word on each line. Example: Line 1: We do... (2 Replies)
Discussion started by: martinsmith
2 Replies
XML::Handler::XMLWriter(3)				User Contributed Perl Documentation				XML::Handler::XMLWriter(3)

NAME
XML::Handler::XMLWriter - a PerlSAX handler for writing readable XML SYNOPSIS
use XML::Parser::PerlSAX; use XML::Handler::XMLWriter; $my_handler = XML::Handler::XMLWriter->new( I<OPTIONS> ); XML::Parser::PerlSAX->new->parse(Source => { SystemId => 'REC-xml-19980210.xml' }, Handler => $my_handler); DESCRIPTION
"XML::Handler::XMLWriter" is a PerlSAX handler for writing readable XML (in contrast to Canonical XML, for example). XML::Handler::XMLWriter can be used with a parser to reformat XML, with XML::DOM or XML::Grove to write out XML, or with other PerlSAX modules that generate events. "XML::Handler::XMLWriter" is intended to be used with PerlSAX event generators and does not perform any checking itself (for example, matching start and end element events). If you want to generate XML directly from your Perl code, use the XML::Writer module. XML::Writer has an easy to use interface and performs many checks to make sure that the XML you generate is well-formed. "XML::Handler::XMLWriter" is a subclass of "XML::Handler::Subs". "XML::Handler::XMLWriter" can be further subclassed to alter it's behavior or to add element-specific handling. In the subclass, each time an element starts, a method by that name prefixed with `s_' is called with the element to be processed. Each time an element ends, a method with that name prefixed with `e_' is called. Any special characters in the element name are replaced by underscores. If there isn't a start or end method for an element, the default action is to write the start or end tag. Start and end methods can use the `"print_start_element()"' and `"print_end_element()"' methods to print start or end tags. Subclasses can call the `"print()"' method to write additional output. Subclassing XML::Handler::XMLWriter in this way is similar to XML::Parser's Stream style. XML::Handler::Subs maintains a stack of element names, `"$self-"{Names}', and a stack of element nodes, `"$self-"{Nodes}>' that can be used by subclasses. The current element is pushed on the stacks before calling an element-name start method and popped off the stacks after calling the element-name end method. See XML::Handler::Subs for additional methods. In addition to the standard PerlSAX handler methods (see PerlSAX for descriptions), XML::Handler::XMLWriter supports the following methods: new( OPTIONS ) Creates and returns a new instance of XML::Handler::XMLWriter with the given OPTIONS. Options may be changed at any time by modifying them directly in the hash returned. OPTIONS can be a list of key, value pairs or a hash. The following OPTIONS are supported: Output An IO::Handle or one of it's subclasses (such as IO::File), if this parameter is not present and the AsString option is not used, the module will write to standard output. AsString Return the generated XML as a string from the `"parse()"' method of the PerlSAX event generator. Newlines A true or false value; if this parameter is present and its value is true, then the module will insert an extra newline before the closing delimiter of start, end, and empty tags to guarantee that the document does not end up as a single, long line. If the paramter is not present, the module will not insert the newlines. IsSGML A true or false value; if this parameter is present and its value is true, then the module will generate SGML rather than XML. print_start_element($element) Print a start tag for `$element'. This is the default action for the PerlSAX `"start_element()"' handler, but subclasses may use this if they define a start method for an element. print_end_element($element) Prints an end tag for `$element'. This is the default action for the PerlSAX `"end_element()"' handler, but subclasses may use this if they define a start method for an element. print($output) Write `$output' to Output and/or append it to the string to be returned. Subclasses may use this to write additional output. TODO
o An Elements option that provides finer control over newlines than the Newlines option, where you can choose before and after newline for element start and end tags. Inspired by the Python XMLWriter. o Support Doctype and XML declarations. AUTHOR
Ken MacLeod, ken@bitsko.slc.ut.us This module is partially derived from XML::Writer by David Megginson. SEE ALSO
perl(1), PerlSAX.pod(3) perl v5.16.3 2003-10-21 XML::Handler::XMLWriter(3)
All times are GMT -4. The time now is 04:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy