Sponsored Content
Top Forums Shell Programming and Scripting SED- Insert text at top of file Post 23322 by peter.herlihy on Thursday 20th of June 2002 07:32:15 PM
Old 06-20-2002
From the command line use
(Note that these must be completed on separate lines.)
This will insert on the first line of the file.

sed '1i\
your text goes here' file_name > new_filename


This will append on the last line of the file.
sed '$a\
your text goes here' file_name > new_filename


Note also that with sed you have to direct the output and rename the file back. So 'mv new_filename file_name' when you are done with these commands.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

insert text into top of file

how would you insert text into a existing file using aguments first arguments being the line of text and the second argument being file name (1 Reply)
Discussion started by: jimbob
1 Replies

2. UNIX for Dummies Questions & Answers

how do I insert argument into TOP of file using vi?

when directing some text into a file can you choose where it goes like the top of the file (which is text aswell) or the middle?? if so how - especially would like to know how to do so in vi (text editor) If i were to enter an argument ($1) into a another argument ($2) would it would be... (6 Replies)
Discussion started by: rprules
6 Replies

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

4. Shell Programming and Scripting

best way to insert a line at the top of a file?

say I want to insert "this is a test" as the first line into file A, besides echo "this is a test" > /tmp/tmpfile cat /tmp/tmpfile fileA >> /tmp/result, is there any simple way I can do it? thanks (7 Replies)
Discussion started by: fedora
7 Replies

5. Shell Programming and Scripting

Insert text file only after the first match with SED

Hello, I'm new in Shell scripting but i should write a script, which inserts the license header out of a txt-File into the files in our Projekt. For the Java classes it runs without Problems but for XML files not. At xml-files i have to put the license Header after the xml-Header (?xml... (1 Reply)
Discussion started by: PhoenixONE
1 Replies

6. Shell Programming and Scripting

Sed insert text at first line of empty file

I can't seem to get sed to allow me to insert text in the first line of an empty file. I have a file.txt that is a 0 byte file. I want sed to insert " fooBar" onto the first line. I've tried a few options and nothing seems to work. They work just fine if there's text in the file tho. Help? (4 Replies)
Discussion started by: DC Slick
4 Replies

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

8. UNIX for Advanced & Expert Users

Insert string in binary file at top

How can i append a EBCDIC string of 100 bytes to 0th position of a binary file in UNIX. (4 Replies)
Discussion started by: param_it
4 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

Insert date/time header at top of file

I'm trying to take mrt output and put it at the top of a file along with the date and time. I was able to do it at the bottom of the file with the following printf "********** $(date) **********\n\n" >> $OUTPUT_PATH/$HOSTNAME mtr -r -w -c 10 $HOSTADDRESS >> $OUTPUT_PATH/$HOSTNAME printf... (2 Replies)
Discussion started by: kramer65
2 Replies
XmDirection(library call)												 XmDirection(library call)

NAME
XmDirection -- Data type for the direction of widget components SYNOPSIS
#include <Xm/Xm.h> DESCRIPTION
XmDirection is the data type specifying the direction in which the system displays subwidgets, children of widgets, or other visual compo- nents that are to be laid out. This data type also affects traversal order within tab groups. XmDirection is implemented as an unsigned char bit mask. The horizontal and vertical directions can be specified independent of each other. XmDirection also specifies the precedence of the horizontal and vertical directions relative to each other. For example, a value of XmRIGHT_TO_LEFT_TOP_TO_BOTTOM lays out a component horizontally from right to left first, then vertically top to bottom. XmDirection provides the following masks, each of which corresponds to a particular bit in XmDirection: o XmRIGHT_TO_LEFT_MASK o XmLEFT_TO_RIGHT_MASK o XmTOP_TO_BOTTOM_MASK o XmBOTTOM_TO_TOP_MASK o XmPRECEDENCE_HORIZ_MASK o XmPRECEDENCE_VERT_MASK In addition to the preceding single bit masks, XmDirection also provides the following multiple bit masks. These multiple bit masks are particularly useful as arguments to XmDirectionMatchPartial: o XmHORIZONTAL_MASK o XmPRECEDENCE_MASK o XmVERTICAL_MASK Motif also provides the following enumerated constants for specifying various combinations of directions: XmRIGHT_TO_LEFT_TOP_TO_BOTTOM Specifies that the components are laid out from right to left first, then top to bottom. XmLEFT_TO_RIGHT_TOP_TO_BOTTOM Specifies that the components are laid out from left to right first, then top to bottom. XmRIGHT_TO_LEFT_BOTTOM_TO_TOP Specifies that the components are laid out from right to left first, then bottom to top. XmLEFT_TO_RIGHT_BOTTOM_TO_TOP Specifies that the components are laid out from left to right first, then bottom to top. XmTOP_TO_BOTTOM_RIGHT_TO_LEFT Specifies that the components are laid out from top to bottom first, then right to left. XmTOP_TO_BOTTOM_LEFT_TO_RIGHT Specifies that the components are laid out from top to bottom first, then left to right. XmBOTTOM_TO_TOP_RIGHT_TO_LEFT Specifies that the components are laid out from bottom to top first, then right to left. XmBOTTOM_TO_TOP_LEFT_TO_RIGHT Specifies that the components are laid out from bottom to top first, then left to right. XmTOP_TO_BOTTOM Specifies that the components are laid out from top to bottom. If horizontal direction is important, do not use this constant. XmBOTTOM_TO_TOP Specifies that the components are laid out from bottom to top. If horizontal direction is important, do not use this constant. XmDEFAULT_DIRECTION Specifies that the components are laid out according to the default direction. (This constant is primarily for widget writers.) XmLEFT_TO_RIGHT Specifies that the components are laid out from left to right. If vertical direction is important, do not use this constant. XmRIGHT_TO_LEFT Specifies that the components are laid out from right to left. If vertical direction is important, do not use this constant. RELATED
XmDirectionMatch(3), XmDirectionMatchPartial(3), XmDirectionToStringDirection(3), XmString(3), XmStringDirection(3), and XmStringDirection- ToDirection(3). XmDirection(library call)
All times are GMT -4. The time now is 07:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy