- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script not working
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
Forums
Discussions
Discussions
Discussions
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
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
02-29-2004 11:49 PM
02-29-2004 11:49 PM
I am trying to use the sed command to change a file however am having difficulty because of some characters in the string I am trying to use - 'date +%d%m'1
for i in spfctl.001.cfg.adhoc spfdat.001.cfg.adhoc
do
cat $i |sed s/'date +%d%m'1/$SPFCHANGE/g >tmpfile
cp tmpfile $i
done
rm tmpfile
if [[ $? != 0 ]]
then
echo "Failed to change the date, please check your syntax"
can someone provide the correct syntax as I have tried numerous ways
thnx
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2004 11:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 02:14 AM
03-01-2004 02:14 AM
Re: script not working
Look at your previous question on the same script where I mentioned that your 'sed' was not going to work and noted on how to fix it.
http://forums1.itrc.hp.com/service/forums/que
stionanswer.do?threadId=471387
//
'date +%d%m' inside sed will be treated as a string.
cat $i |sed s/'date +%d%m'/$SPFCHANGE/g >tmpfile
Modify the above as follows
DATE=$(date +%d%m)
sed 's/'${DATE}'/'$SPFCHANGE'/g' $i > tmpfile
//
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 03:59 AM
03-01-2004 03:59 AM
Re: script not working
I have attempted this however the file that I am trying to change the string in isn't happening.
any other suggestions?
Tnx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 04:06 AM
03-01-2004 04:06 AM
Re: script not working
Actually, on my system `date`is not treated as a string by "sed". It does what you would hope :)
Lawrenzo,
If you remove the single quotes around your variabel and use Sridhars method it should work.
i.e.
$DATE=$(date +%d%m)1 # assuming that "1" isn't a typo
cat $i| sed "s/$DATE/$SPFCHANGE/g" > tmpfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 04:08 AM
03-01-2004 04:08 AM
Re: script not working
could you show us a few lines of input?
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 04:11 AM
03-01-2004 04:11 AM
Re: script not working
I agree. But he was using quotes instead of backticks unlike you. So, I gave him DATE=$(...) answer in the other post.
Lawrenzo,
Can you post a sample of data?. I believe your input files do not contain the pattern given by date +%d%m command.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 04:27 AM
03-01-2004 04:27 AM
Re: script not working
TRANSFER_TYPE=send
LOCAL_FILEPATH=/sas/analysis/four/sigpack/util/data01/prod/sas_output/SIG`date +%d%m`1.dat
REMOTE_FILEPATH=/data/cdirect/transit/prod_spf/SIG`date +%d%m`01.dat
I know the second string here is `01 therefor the original for i in * will be run twice within the script unless there is another way?
Thanks again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 05:14 AM
03-01-2004 05:14 AM
Re: script not working
maybe I do not understand, but have you tried this:
sed s/'`date +%d%m`01'/$SPFCHANGE/g
or just
sed s/'`date +%d%m`'/$SPFCHANGE/g
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 05:21 AM
03-01-2004 05:21 AM
Re: script not working
There are about three answers here that will probably work, have you actually tried them? we haven't had any feedback from you.
I would suggest cut & paste for the sed commands because the type of quote marks you use is important and not too easy to see in a web browser.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 05:25 AM
03-01-2004 05:25 AM
Re: script not working
sed 's/\`date +%d%m\`1/'$SPFCHANGE'/g' data > tmpfile
Escape (\) the backticks (`) and see if it works.
As Mark said, copy and paste the code otherwise, you will get confused between back ticks and quotes.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2004 06:55 PM
03-01-2004 06:55 PM
Re: script not working
Sorry for the late response, I was away from my desk most of today,
Thanks for the solutions, Mark and Sri's syntax both work
many thanks
Lawrenzo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2004 05:07 AM
03-02-2004 05:07 AM
Re: script not working
for i in spfctl.001.cfg.adhoc spfdat.001.cfg.adhoc
do
cat $i |sed s/$(date +%d%m)1/$SPFCHANGE/g >tmpfile
cp tmpfile $i
done