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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to insert new text and change existing text in a file using SED
# 1  
Old 11-20-2008
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: $ahi...

Can anyone please help me to solve my issue??
Thanks in advance!!!
Geetha
# 2  
Old 11-20-2008
Hi geetha,

Pls. paste your file contents here and the output required out of it.

Regards,
Vinod.

Quote:
Originally Posted by iamgeethuj
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: $ahi...

Can anyone please help me to solve my issue??
Thanks in advance!!!
Geetha
# 3  
Old 11-20-2008
Let we take the contant of the file shell as.
12 routine
13 shell

and I need a new file shell1 with the content of shell along with the appended contant "hi..."
# 4  
Old 11-20-2008
Try:

Code:
sed 's/shell/& hi.../' shell > shell1

# 5  
Old 11-25-2008
We could use the following:

awk '{print $0 " hi...."}' shell > shell1


Regards,
Vinod.

Quote:
Originally Posted by Franklin52
Try:

Code:
sed 's/shell/& hi.../' shell > shell1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command not working for me to change text in a file

UNIX gurus I need your help with the following (The server is an AIX box). I have a text file with the following information: ******************************************************** SOME LINES case :WORD1 SOME LINES :WORD2 SOME LINES :WORD3 SOME LINES esac SOME LINES... (7 Replies)
Discussion started by: curiousmal
7 Replies

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

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

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

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

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

7. Shell Programming and Scripting

how to insert text between lines of an existing file using perl

Hi , I need some inputs on how to open a file (file.txt) and parse the text example aaa of the file and bbb of the file and add the text zzzz once i parse (aaa and bbb) and followed by the remaining of the text as it is in the file using perl programming. Thanks in advance (3 Replies)
Discussion started by: madhul2002
3 Replies

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

9. UNIX for Dummies Questions & Answers

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. #!/bin/sh touch textfile.txt sed 'i\ Add this line before every line with WORD' textfile.txt ... (5 Replies)
Discussion started by: steveramsey
5 Replies

10. Shell Programming and Scripting

SED- Insert text at top of file

Does anyone know how to insert text at the top and bottom of a file using sed? (12 Replies)
Discussion started by: MBGPS
12 Replies
Login or Register to Ask a Question