Sponsored Content
Full Discussion: Insert Text With Sed
Top Forums UNIX for Dummies Questions & Answers Insert Text With Sed Post 98492 by steveramsey on Wednesday 8th of February 2006 03:41:44 PM
Old 02-08-2006
Insert Text With Sed

Hello. Trying to insert text at line 1 and after last line of file. I have searched posts but nothing seems to work. I keep getting extra characters error or nothing gets inserted into the file.

Code:
#!/bin/sh
touch textfile.txt
sed 'i\
Add this line before every line with WORD' textfile.txt

Help please. Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to insert new text and change existing text in a file using SED

Hi all, I need to insert new text and change existing text in a file. For that I used the below line in the command line and got the expected output. sed '$a\ hi... ' shell > shell1 But I face problem when using the same in script. It is throwing the error as, sed: command garbled:... (4 Replies)
Discussion started by: iamgeethuj
4 Replies

2. Shell Programming and Scripting

sed insert text at particular line

I know that sed -n '12p' file will print line 12 but how might I insert text to a specified line? thanks (2 Replies)
Discussion started by: action_owl
2 Replies

3. Shell Programming and Scripting

Insert text with Sed (in various positions)

Hello. I'm trying to insert text in various positions and I could only do that using pipes for each position. Example: cat file | sed -e 's#\(.\{5\}\)\(.*\)#\1:\2#g' | sed -e 's#\(.\{26\}\)\(.*\)#\1:\2#g' Insert ":" at position 5 and 26. it can be done in the same sentence, without using... (4 Replies)
Discussion started by: </kida>
4 Replies

4. Shell Programming and Scripting

sed insert text without newline

Hi, I use sed to insert text at beginning of a file. But sed inserts a newline after my text that I do not need. For example, I want to insert "foo" at the beginning of my file: > cat myfile This is first line. > sed -i '1i\foo' myfile > cat myfile foo This is first line. ... (5 Replies)
Discussion started by: tdw
5 Replies

5. Shell Programming and Scripting

Using sed to insert text file at first line

sed '1r file.txt' <source.txt >desti.txt This example will insert 'file.txt' between line 1 and 2 of source.txt. sed '0r file.txt' <source.txt >desti.txt gives an error message. Does anyone know how 'sed' can insert 'file.txt' before the first line of source.txt? (18 Replies)
Discussion started by: psve
18 Replies

6. Shell Programming and Scripting

sed to insert a slash and keep text

I have: /path/to/my/fixdir/MD1234567.tar I want to have: /path/to/my/fixdir/MD/1234567.tar fixdir never changes but MD does and how many numerical digits does. I want something like: /usr/bin/sed 's/fixdir\/../fixdir\/..\//' This ends up: /path/to/my/fixdir/../1234567.tar But... (3 Replies)
Discussion started by: crowman
3 Replies

7. Shell Programming and Scripting

Insert text using sed

sed 's/$/TEST/g' will insert TEST at the end of each line. i want to insert TEST at column 64 (7 Replies)
Discussion started by: lawsongeek
7 Replies

8. Shell Programming and Scripting

sed insert text 2 lines above pattern

Hi I am trying to insert a block of text 2 lines above a pattern match using sed eg #Start of file entry { } #End of file entry new bit of text has to be put in just above the } eg #Start of file entry { New bit of text } #End of file entry (7 Replies)
Discussion started by: eeisken
7 Replies

9. Shell Programming and Scripting

How do I insert text with sed ?

Hi I was wondering if anyone new of a solution to this problem? I need to copy a time stamp that is on a line of .text in a text file into multiple positions on the same line. I need to insert the time stamp on the same line between every occurance of the text ".pdf_.html" right after the... (9 Replies)
Discussion started by: Paul Walker
9 Replies

10. Shell Programming and Scripting

Using sed to insert text between lines

Hello, I am trying to insert a section of text between lines in another text file. The new lines to be inserted are: abcd.efgh.zzzz=blah abcd.efgh.xxxx=blah Where N = 0 to 2 Original File: abcd.efgh.wwxx=aaaaa abcd.efgh.yyzz=bbbbb abcd.efgh.wwxx=aaaaa abcd.efgh.yyzz=bbbbb... (3 Replies)
Discussion started by: tsu3000
3 Replies
ntextBindings(n)				     Alternative Bindings for the Text Widget					  ntextBindings(n)

__________________________________________________________________________________________________________________________________________________

NAME
ntextBindings - Alternative Bindings for the Text Widget SYNOPSIS
package require Tcl 8.5 package require Tk 8.5 package require ntext ?0.81? _________________________________________________________________ DESCRIPTION
The ntext package provides a binding tag named Ntext for use by text widgets in place of the default Text binding tag. The Text binding tag provides around one hundred bindings to the text widget (the exact number is platform-dependent). A few of these behave in a way that is different from most contemporary text-editing applications. Ntext aims to provide more familiar behaviour. Features of the Ntext bindings that differ from the default Text bindings: o Clicking near the end of a (logical) line moves the cursor to the end of that line (not the start of the next line). If the widget is in -wrap word mode, the same rule applies to display lines. o Double-clicking or dragging near the end of a (logical) line will highlight/select characters from the end of that line (not the next line, or the region at the end of the line where there are no characters). If the widget is in -wrap word mode, the same rule applies to display lines. o The End key implements "Smart End" (successive keypresses move the cursor to the end of the display line, then to the end of the logical line); the Home key implements "Smart Home" (which is similar to "Smart End", but also toggles between the beginning and end of leading whitespace). o When a selection exists, a <<Paste>> operation (e.g. <Control-v>) overwrites the selection (as most editors do), and does so on all platforms. o The <Insert> key toggles between "Insert" and "Overwrite" modes for keyboard input. (In contrast, the Text binding tag uses <Insert> as a method to paste the "primary selection", a task that can be accomplished instead by mouse middle-click.) o The <Escape> key clears the selection. o Selecting with <Shift-Button1> selects from the previous position of the insertion cursor. (In the Text binding tag, the selection anchor may be the position of the previous mouse click.) o <Shift-Button1> operations do not alter the selection anchor. (In the Text binding tag, they do.) o By default, the Ntext binding tag does not provide several of the Control-key bindings supplied by the Text binding tag. Modern keyboards offer alternatives, such as cursor keys for navigation; modern applications often use the Control-key bindings for other purposes (e.g. <Control-p> for "print"). The last three cases, the behavior of Text is often useful, so Ntext gives you the option of retaining it, by setting variables defined in the ::ntext namespace to 1 (instead of their default 0). Explaining these features in more detail: o If the mouse is clicked at position A, then the keyboard is used to move the cursor to B, then shift is held down, and the mouse is clicked at C: the Text binding tag gives a selection from A to C; the Ntext gives a selection from B to C. If you want Ntext to behave like Text in this respect, set ::ntext::classicMouseSelect to 1. o The Text binding tag allows successive <Shift-Button-1> events to change both ends of the selection, by moving the selection anchor to the end of the selection furthest from the mouse click. Instead, the Ntext binding tag fixes the anchor, and multiple Shift-But- ton-1 events can only move the non-anchored end of the selection. If you want Ntext to behave like Text in this respect, set ::ntext::classicAnchor to 1. In both Text and Ntext, keyboard navigation with the Shift key held down alters the selection and keeps the selection anchor fixed. o The following "extra" Text bindings are switched off by default, but can be activated in Ntext by setting ::ntext::classicExtras to 1: <Control-a>, <Control-b>, <Control-d>, <Control-e>, <Control-f>, <Control-h>, <Control-i>, <Control-k>, <Control-n>, <Control-o>, <Control-p>, <Control-t>, <Control-space>, <Control-Shift-space>. CONFIGURATION OPTIONS
Ntext provides alternatives to a number of behaviours of the classic Text binding tag. Where there is an option, the Ntext behaviour is switched on by default, except for display-line indentation which is discussed on a separate page at ntextIndent. The behaviour of Ntext may be configured application-wide by setting the values of a number of namespace variables: ::ntext::classicAnchor o 0 - (default value) selects Ntext behaviour, i.e. the anchor point is fixed o 1 - selects classic Text behaviour, i.e. the anchor point is variable ::ntext::classicExtras o 0 - (default value) selects Ntext behaviour, i.e. several "extra" Text bindings are de-activated o 1 - selects classic Text behaviour, i.e. the "extra" Text bindings are activated ::ntext::classicMouseSelect o 0 - (default value) selects Ntext behaviour, i.e. the anchor point for mouse selection operations is moved by keyboard navigation o 1 - selects classic Text behaviour ::ntext::overwrite o 0 - (initial value) text typed at the keyboard is inserted into the widget o 1 - text typed at the keyboard overwrites text already in the widget o The value is toggled by the Insert key. EXAMPLE
To use Ntext but keep classic Text 's variable-anchor feature: package require ntext text .t set ::ntext::classicAnchor 1 bindtags .t {.t Ntext . all} SEE ALSO
bindtags, ntext, ntextIndent, text KEYWORDS
bindtags, text ntext 0.81 ntextBindings(n)
All times are GMT -4. The time now is 04:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy