- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: sed help please
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2009 12:06 AM
тАО03-02-2009 12:06 AM
1, if there is no ip address of ntp server, then provide it in the /etc/ntp.conf
2, if /etc/ntp.conf contains the wrong IP address of NTP server, then fix it.
Problem:
following doesnt work
cat /etc/ntp.conf.org | sed 's/$CHECK_SERVER/$STRING/' > /etc/ntp.conf
i.e sed doesnt substitute the value of a variable $CHECK_SERVER with the value of another variable "$STRING"
please help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2009 12:29 AM
тАО03-02-2009 12:29 AM
Re: sed help please
echo "$CHECK_SERVER -> $STRING"
and see what the result give you.
I believe this is because in your CHECK_SERVER string you've done an thought error.
CHECK_SERVER=$(grep ^server /etc/ntp.conf | grep -v '127.127.1.0' | cut -f2 -d" ")
The cut will give you the result "192.168.0.1" instead of "server 192.168.0.1" which is what you really wanted.
Use the echo method above to verify this, but I think this is the reason.
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2009 02:11 AM
тАО03-02-2009 02:11 AM
Re: sed help please
and thanks for the suggestion
I did a test
# cat file
this is maaz
# cp file file.old
# echo $STRING1
this is maaz
# echo $STRING2
this is NOT maaz
# cat file.old | sed 's/$STRING1/$STRING2/' > file
# cat file
this is maaz
i.e no change in the 'file'
please help me in substituting the values of variables via 'sed'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2009 03:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2009 03:28 AM
тАО03-02-2009 03:28 AM
Re: sed help please
It should have if string1="this is maaz" and the file contains "this is maaz".
Something you should know thou is that sed regexps are case sensitive, if you add a "i" at the end (ex. s/pattern/replace/i) this will change the sed regexp to match case insensitive ("A" and "a" will be matched as the same character).
I would try to do this manually first as an experiment.
# sed -e "s/192.168.0.2/192.168.0.1/" /etc/ntp.conf
This won't change the file just the output given to you in your shell.
If this works I would try adding one of the variables.
# sed -e "s/$CHECK_SERVER/192.168.0.1/" /etc/ntp.conf
And so on untill you find the reason why it wasn't changed.
Also I would recommend using only sed to change the file.
# cp /etc/ntp.conf /etc/ntp.conf.org
# sed -i "s/$CHECK_SERVER/$STRING/" /etc/ntp.conf
-i tells sed to change the file with the search-replace-expression :)
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2009 11:18 PM
тАО03-02-2009 11:18 PM
Re: sed help please
and thanks Dear Fredrik.eriksson for your continuous support and suggestions and excellent tips
another relevant question
the following code has to do two task
1, if there is no TIMEZONE set, then set it in /etc/sysconfig/clock
2, if there is wrong TIMEZONE in /etc/sysconfig/clock, then fix it
ok, now
the proper value of timezone in /etc/sysconfig/clock should be
TIMEZONE="Asia/Tashkent"
right now the value of timezone(wrong) in /etc/sysconfig/clock is
TIMEZONE="aa/tshknt"
#!/bin/bash
CLOCK=/etc/sysconfig/clock
TIMEZONE_STRING='TIMEZONE="Asia/Tashkent"'
CHECK_TIMEZONE=$(grep ^TIMEZONE $CLOCK)
if [ -z "$CHECK_TIMEZONE" ]; then echo "$TIMEZONE_STRING" >> $CLOCK
else cp "$CLOCK" /tmp/clock
cat /tmp/clock | sed "s/$CHECK_TIMEZONE/$TIMEZONE_STRING/" > $CLOCK
fi
exit
upon execution of the above code, I got the following error
sed: -e expression #1, char 36: unknown option to `s'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2009 12:04 AM
тАО03-03-2009 12:04 AM
Re: sed help please
sed -i "s/TIMEZONE=\".*\"/TIMEZONE="Asia/Tashkent/" /etc/sysconfig/clock
Since you always want it to be the same way and not dependent on what the previous value was this would be a simpler solution.
This ofcourse sets the prerequisite that the variable string itself actually exists thou. Which it should.
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2009 12:05 AM
тАО03-03-2009 12:05 AM
Re: sed help please
sed -i "s/TIMEZONE=\".*\"/TIMEZONE="Asia\/Tashkent/" /etc/sysconfig/clock
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2009 01:08 AM
тАО03-03-2009 01:08 AM
Re: sed help please
>sry, I missed a vital part.
>sed -i "s/TIMEZONE=\".*\"/TIMEZONE="Asia\/Tashkent/" /etc/sysconfig/clock
Dear when I copy and paste the above "sed" on terminal, it didnt execute
# sed -i "s/TIMEZONE=\".*\"/TIMEZONE="Asia\/Tashkent/" /etc/sysconfig/clock
>
(here I type ctrl+c, to get the prompt back)
but following works
# sed -i 's/TIMEZONE=\".*\"/TIMEZONE="Asia\/Tashkent/' /etc/sysconfig/clock
i.e i used ' instead of "
thanks for your kind support,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-03-2009 01:29 AM
тАО03-03-2009 01:29 AM
Re: sed help please
sed -i "s/TIMEZONE=\".*\"/TIMEZONE=\"Asia\/Tashkent\"/" /etc/sysconfig/clock
You need to escape qoutes that is inside of the search-replace expression.
Best regards
Fredrik Eriksson