03-13-2008
insert text in the middle of a file
I want to insert a text into the middle of a file
10 More Discussions You Might Find Interesting
1. Programming
I have a problem that I want to insert and delete some chars in the middle of a file. fopen() and fdopen() just allow to append at the end.
Is there any simple method or existing library that allow these actions? Thanks in advance.:confused: (7 Replies)
Discussion started by: ivancheung
7 Replies
2. Shell Programming and Scripting
how do u insert text into a specific place in a file, say the middle for example, without changing the name for that file (1 Reply)
Discussion started by: mopimp
1 Replies
3. Shell Programming and Scripting
Script 1
Pre-requisites
Create a file with x amount of lines in it, the content of your choice.
Write a script that takes two arguments. The first being a line of text, the second being your newly created file. The script should take the first argument and insert it into the very top (the... (3 Replies)
Discussion started by: ali hussain
3 Replies
4. Shell Programming and Scripting
I wrote a script like
#!/bin/bash
echo $1 > temp
cat $2 >> temp
mv temp $2
now I have problem appending the above script(only using bash shell) so that it now inserts the first argument into the middle of the file.
I have tried using $(('wc -l < file' / 2 ))
but invain so could any one... (4 Replies)
Discussion started by: boris
4 Replies
5. Shell Programming and Scripting
how to insert one file into another file not by concatenating as usual done.
file1
A B
C D
E F
G H
I J
K L
file2
23455
33444
33334
33345
Output shud be
23455
A B
C D (4 Replies)
Discussion started by: cdfd123
4 Replies
6. Shell Programming and Scripting
Can anyone help me pls? I want to add a text into the middle of file.
I've writtenthe following script
text to add="$1"
file="$2"
lines=$(wc -l $2)
half_lines=$(expr $lines / 2)
head -$half_lines $2 > temp
echo "text to add" >> temp
((half_lines=$half_lines + 1))
tail -$half_lines $2... (6 Replies)
Discussion started by: relle
6 Replies
7. UNIX for Dummies Questions & Answers
Hey guys, how do we take a line of text as an argument from a user and then insert it in the middle of a file irrespective of the number of lines in the file. I am trying to do this without SED or AWK. Inserting it in the beginning and at the end is easy, but i am trying to accomplish inserting... (6 Replies)
Discussion started by: kartikkumar84@g
6 Replies
8. Shell Programming and Scripting
I have tried
sed '/6/a text_to_inserted' file > newfile
but this inserts test_to_insert at random places in file and i want it in specific location, which is line 6.
can anyone help.... (6 Replies)
Discussion started by: phenom
6 Replies
9. Shell Programming and Scripting
Hi I am trying to write a bash script to add a line of text to the middle of a file.
The way I worked it out was to calculate the number of lines and divide by 2. The file I am using is called newfile and it just contains lines of data.
The new file I have created I have called midfile and... (7 Replies)
Discussion started by: BundBash
7 Replies
10. Shell Programming and Scripting
Hi,
So far i've made a script that takes two argument, 1st is the contents and the 2nd is the named file. At the moment i've managed to insert new contents as a new line at the top, but i want to ask how can you insert contents in the middle of the file?
Source Code
#!/bin/bash
#Write... (3 Replies)
Discussion started by: zen10
3 Replies
LEARN ABOUT DEBIAN
gtk2::editable
Gtk2::Editable(3pm) User Contributed Perl Documentation Gtk2::Editable(3pm)
NAME
Gtk2::Editable - wrapper for GtkEditable
HIERARCHY
Glib::Interface
+----Gtk2::Editable
METHODS
string = $editable->get_chars ($start_pos, $end_pos)
o $start_pos (integer)
o $end_pos (integer)
$editable->copy_clipboard
$editable->cut_clipboard
$editable->delete_selection
$editable->delete_text ($start_pos, $end_pos)
o $start_pos (integer)
o $end_pos (integer)
boolean = $editable->get_editable
$editable->set_editable ($is_editable)
o $is_editable (boolean)
new_position = $editable->insert_text (new_text, position)
o $new_text (string)
o ... (list)
$editable->paste_clipboard
integer = $editable->get_position
$editable->set_position ($position)
o $position (integer)
$editable->select_region ($start, $end)
o $start (integer)
o $end (integer)
(start, end) = $editable->get_selection_bounds
Returns integers, start and end.
SIGNALS
changed (Gtk2::Editable)
insert-text (Gtk2::Editable, string, integer, gpointer)
delete-text (Gtk2::Editable, integer, integer)
The "insert-text" signal handler can optionally alter the text to be inserted. It may
o Return no values for no change. Be sure to end with an empty "return".
sub my_insert_text_handler {
my ($widget, $text, $len, $pos, $userdata) = @_;
print "inserting '$text' at char position '$pos'
";
return; # no values
}
o Return two values "($text, $pos)" which are the new text and character position.
sub my_insert_text_handler {
my ($widget, $text, $len, $pos, $userdata) = @_;
return (uc($text), $pos); # force to upper case
}
o Return no values and modify the text in $_[1] and/or position in $_[3]. For example,
sub my_insert_text_handler {
$_[1] = uc($_[1]); # force to upper case
$_[3] = 0; # force position to the start
return; # no values
}
Note that currently in a Perl subclass of a "Gtk2::Editable" widget, a class closure (ie. class default signal handler) for "insert-text"
does not work this way. It instead sees the C level "($text, $len, $pos_pointer)", where $pos_pointer is a machine address and cannot be
used easily. Hopefully this will change in the future. A "signal_chain_from_overridden" with the args as passed works, but for anything
else the suggestion is to use a "signal_connect" instead.
SEE ALSO
Gtk2, Glib::Interface
COPYRIGHT
Copyright (C) 2003-2011 by the gtk2-perl team.
This software is licensed under the LGPL. See Gtk2 for a full notice.
perl v5.14.2 2012-05-27 Gtk2::Editable(3pm)