sed changes go to standard out....?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed changes go to standard out....?
# 1  
Old 03-26-2008
sed changes go to standard out....?

Hi gang: Need some help with "sed". The script below is working except for the sed command. It does replace the words I'm searching for but the change goes to standard out (screen) so the file is not updated. How do I get sed to modify the file?? I'm sure it something simple...
Thanks All !!! This is running Solaris 8

#! /bin/sh

# Begin shell script to modify the netmap

echo "Welcome to the netmap edit tool"
echo "What would you like to do?"

echo 1. Add a node to the netmap
echo 2. Modify a node in the netmap
echo 3. Delete a node in the netmap.

read choice
# Begin choice determination logic

if [ $choice = 1 ]
then
# logic to add a new node to current netmap

cat newnode >> netmap.cfg

# New Node info collection
echo " Enter the new node name"
read newnodename

sed "s/bogus/$newnodename/" netmap.cfg

echo "Enter IP address of new node"
read IP

sed "s/ipaddress/$IP/" netmap.cfg

else
echo "Still under construction"
fi
# 2  
Old 03-26-2008
use sed -ie
# 3  
Old 03-26-2008
sed -ie "s/bogus/$newnodename/" netmap.cfg
# 4  
Old 03-26-2008
Hmmm... Here is the outcome.. Doesn't seem to like the "i".

Enter the new node name
JJJJJJJ
Enter IP address of new node
100.10.0
sed: illegal option -- i


New code:
# New Node info collection
echo " Enter the new node name"
read newnode

echo "Enter IP address of new node"
read IP

sed -ie "s/bogus/$newnode/" netmap.cfg
# 5  
Old 03-26-2008
If your sed doesn't have the -i option, you will need to redirect to a temporary file, then move the temporary file over the original file.

You can do both substitutions in a single sed script after you collected all the user input.

Code:
sed -e "s/bogus/$newnodename/" -e "s/ipaddress/$IP/"

Your first beta tester will want to input an IP address with a slash in it, and then you're screwed (^:
# 6  
Old 03-26-2008
Man... this was subtle... Here's the answer... has to redirect to a tmpfile and then cat to the file I'm using.... Thanks for the help era you got me pointed in the right direction..

# Begin choice determination logic

if [ $choice = 1 ]
then
# logic to add a new node to current netmap

# New Node info collection
echo " Enter the new node name"
read newnode

echo "Enter IP address of new node"
read IP

sed -e "s/bogus/$newnode/" -e "s/ipaddress/$IP/" newnode >tmpnode
cat tmpnode >> netmap.cfg

rm tmpnode

else
echo "Still under construction"
fi
# 7  
Old 03-26-2008
Actually if you are always appending to netmap.cfg then you don't need the temporary file at all.

Code:
sed -e "s/bogus/$newnode/" -e "s/ipaddress/$IP/" newnode >>netmap.cfg

Sorry, I missed this detail.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed with standard input not working

I am trying use sed to replace a string in a file with input string passed, but it is not replacing the string. instead it replace as $1. Please find below the code. echo $1 sed -i.$now "s/http.*.myservice.*.war/$1/" tempfile.xml I am running above code as below myscript.sh ReplaceString... (4 Replies)
Discussion started by: sakthi.99it
4 Replies

2. Shell Programming and Scripting

sed command works from cmd line to standard output but will not write to file

Hi all .... vexing problem here ... I am using sed to replace some special characters in a .txt file: sed -e 's/_<ED>_/_355_/g;s/_<F3>_/_363_/g;s/_<E1>_/_341_/g' filename.txt This command replaces <ED> with í , <F3> with ó and <E1> with á. When I run the command to standard output, it works... (1 Reply)
Discussion started by: crumplecrap
1 Replies

3. Shell Programming and Scripting

Standard out and standard error

I need to run a cronjob and in the cronjob I execute a script that if there is an error produces standard error so I do /RUNMYSCRIPT 2> mylogfile.log However, if it runs correctly, I don't get a standard error output, I get a standard out output. How do I redirect both standard error and... (2 Replies)
Discussion started by: guessingo
2 Replies

4. UNIX for Dummies Questions & Answers

Redirect Standard output and standard error into spreadsheet

Hey, I'm completely new at this and I was wondering if there is a way that I would be able to redirect the log files in a directories standard output and standard error into and excel spreadsheet in anyway? Please remember don't use too advanced of terminology as I just started using shell... (6 Replies)
Discussion started by: killaram
6 Replies

5. Solaris

standard input

Please give me any example for standard input in Solaris. (6 Replies)
Discussion started by: karman0931
6 Replies

6. Shell Programming and Scripting

standard error to standard out question

Hi there how can i get the result of a command to not give me its error. For example, on certain systems the 'zfs' command below is not available, but this is fine becaues I am testing against $? so i dont want to see the message " command not found" Ive tried outputting to /dev/null 2>&1 to no... (5 Replies)
Discussion started by: hcclnoodles
5 Replies

7. Shell Programming and Scripting

Sed does not make changes in the file but to the standard output

I have an xml file. I am doing some change, say deleting line 770. File name is file.xml. I use: sed '770d' file.xml but this does not actually make changes in the *file* but shows the changes on standard output (screen) if i use $var=`sed '770d' file.xml` echo $var > file.xml this... (3 Replies)
Discussion started by: indianjassi
3 Replies

8. UNIX for Advanced & Expert Users

To know the standard

Dear all, I have a need to find the standard of my system such as POSIX. How can I know that. Is there any way to find it. I am using GNU/Linux. (2 Replies)
Discussion started by: nagalenoj
2 Replies

9. HP-UX

v2 standard libraries

I am a bit confused about the use of _v2 standard libraries on HP. I am working on HP11.11 risk machine and HP 11.23 Itanium machine. I am building a C++ shared library which is linked by a JNI shared library and other non-java related libraries. Eveything is compiled with -AA flag. When I... (0 Replies)
Discussion started by: cactuar
0 Replies

10. UNIX for Advanced & Expert Users

what can I get the posix standard?

I wanted study and write a unix like system. who can help me. ------------- Removed the garbled characters... not sure why they were there... (2 Replies)
Discussion started by: crashsky
2 Replies
Login or Register to Ask a Question