Visit Our UNIX and Linux User Community


problem with sed for inserting command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem with sed for inserting command
# 1  
Old 09-30-2009
problem with sed for inserting command

Hello,
i use sed '/good/ a\INSERT' 1.txt command for insert a text on my file on linux butit does not work see the output :

Code:
[root@server t]# sed '/good/ a\INSERT' 1.txt
if_test=iso
ifup=eth0
Hello
World
Bye
now
good
INSERT
[root@server t]# cat 1.txt
if_test=iso
ifup=eth0
Hello
World
Bye
now
good
[root@server t]#

with sed '/good/ a\INSERT' 1.txt it will insert but when i want editing it it does not include "INSERT" would you help me what is wrong withit?

Thank You,
# 2  
Old 09-30-2009
use -i option with sed command.

Code:
$ sed -i  '/good/ a\INSERT' 1.txt


Previous Thread | Next Thread
Test Your Knowledge in Computers #854
Difficulty: Medium
React (also known as React.js or ReactJS) is a JavaScript library maintained by Facebook for building user interfaces.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Problem with using sed command

I have tried to print the commands which are executed today from history file using sed command by putting the range but i am unable to get it.can anyone help with this is script.I am pasting the script below that i have tried . today=$(date "+%F") echo $today yest=$(date --date="yesterday" ... (2 Replies)
Discussion started by: iosjsk
2 Replies

2. UNIX for Dummies Questions & Answers

sed command problem

Hi i am reading a tutorial on sed below command was given in tutorial. i am not able to understand the working of below command also this command is now working in my enviroment. $ sed -n '1~2p' alarm sed: 1: "1~2p": invalid command code ~ $ need your assitance here (7 Replies)
Discussion started by: scriptor
7 Replies

3. Shell Programming and Scripting

[Solved] SED - Bash - Inserting multi Tab character in the command

Hello. I am using : sed -i -e '/žname_scriptž/a#'"${MY_TAB11}"'# \ #'"${MY_TAB1}"'The Standard way'"${MY_TAB7}"'# \ #'"${MY_TAB1}"'==============='"${MY_TAB7}"'# \ ' "$CUR_FILE" Is there a better way to define "MY_TAB7","MY_TAB11" in other way than : MY_TAB1=$'\t' MY_TAB2=${MY_TAB1}$'\t'... (2 Replies)
Discussion started by: jcdole
2 Replies

4. Shell Programming and Scripting

Inserting text with SED

Hi guys, I need to insert @test.com after each entry in my .txt file. 1 2 3 4 1@test.com 2@test.com 3@test.com 4@test.com Tried to use cat test.txt |sed 's/$/@test.com/'but it does this instead: 1 @test.com 2 (6 Replies)
Discussion started by: spirm8
6 Replies

5. Shell Programming and Scripting

i need help in sed command problem

i use 'sed' with this syntax " sed "/$lineerr/d" $fileerr > $fileerr"_Bak" && mv $fileerr"_Bak" $fileerr" it's work to remove the line that have the word in $lineerr but it also remove my last line in file too. - -" my input File $ cat fileerr.txt xx|1111111111 xx|2222222222... (5 Replies)
Discussion started by: Chalot99
5 Replies

6. Shell Programming and Scripting

SED command problem

hi frnds, my data file goes like this sessioj123 ffl sfootxt sgsggs TARG ROW aaa :123 bbb : 145 ccc: 669 vvv: 777 ) my output should be 123,145,669,777. we can identify the data block using the keywor TARG ROW and ). Plz help how to implement using SED commands in shell... (8 Replies)
Discussion started by: Gopal_Engg
8 Replies

7. UNIX for Dummies Questions & Answers

Problem with sed command

Hi, I used sed command to replace § character. sed -n '1,$s/§/o/gp' inputfile > outputfile The problem is there are 5 records in input file and 2 records has that § character. So after using the sed command, in output file Iam getting only those records which has character § replaced by o.... (2 Replies)
Discussion started by: manneni prakash
2 Replies

8. Shell Programming and Scripting

problem in sed command

Hi, i have a script to replace a string. $ cat List.txt /DIR1/DIR2/DIR3/abcdefgh /DIR1/DIR2/DIR3/abcd /DIR1/DIR2/DIR3/abcdefghijk /DIR1/DIR2/DIR3/xyz $ ind=`/DIR1/DIR2/DIR3/abcd` $ replace=`#/DIR1/DIR2/DIR3/abcd` $ sed "s|$find|$replace|g" List.txt>cat NewList.txt The aim of... (3 Replies)
Discussion started by: tsaravanan
3 Replies

9. Shell Programming and Scripting

sed command problem

hi I am using "sed" command to find and replace a text in a file. if the searched string is in the last line with no newline character in the end, it doesn't retrive this line. What is the solution to this? i am using sed as: sed -e "s/abc/ABC/g" test.txt where i am replacing abc with ABC (11 Replies)
Discussion started by: dharmesht
11 Replies

10. Shell Programming and Scripting

Sed command problem

Hi! here is my problem : $ more file yopyop:FIToB8df02f:10200:351:yoyo:/home/yopyop:/usr/bin/ksh $grep yopyop file | sed s/FIToB8df02f/passe/ yopyop:passe:10200:351:yoyo:/home/yopyop:/usr/bin/ksh $more file yopyop:FIToB8df02f:10200:351:yoyo:/home/yopyop:/usr/bin/ksh ...when i... (1 Reply)
Discussion started by: tomapam
1 Replies

Featured Tech Videos