![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell Script: want to insert values in database when update script runs | ring | Shell Programming and Scripting | 1 | 10-25-2007 04:06 AM |
| Shell script to append a time for the existing error log file | gsprasanna | UNIX for Advanced & Expert Users | 12 | 07-12-2007 06:07 AM |
| sql query results in unix shell script | skyineyes | UNIX for Dummies Questions & Answers | 1 | 06-20-2007 11:56 AM |
| How to insert new line in the data file using the script | Sona | UNIX for Dummies Questions & Answers | 2 | 08-22-2006 02:17 AM |
| How to input username on text file into finger command on shell script | Micz | Shell Programming and Scripting | 3 | 11-08-2005 02:38 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
script to run shell command and insert results to existing xml file
Hi. Thanks for any help with this. I'm not new to programming but I am new to shell programming. I need a script that will
1. execute 'df -k' and return the volume names with specific text 2. surround each line of the above results in opening and closing xml tags 3. insert the results of step #2 into an existing file after a specific opening xml tag. Any help would be greatly appreciated! littlejon ![]() |
|
|||||
|
You can try something like that : Code:
result_file=df.dat
open_tag='<TAG>'
close_tag='</TAG>'
insert_point='<XML>'
df_file=/tmp/$$.tmp
temp_file=/tmp/$$.tmp
# Build lines to be inserted in result file
df -k | tail +2 | while read line
do
echo "${open_tag}\n${line}\n${close_tag}"
done >> ${df_file}
# Insert lines in result file
sed -e "/${insert_point}/r ${df_file}" ${result_file} > ${temp_file}
mv ${temp_file} ${result_file}
Jean-Pierre. |
| Bits Awarded / Charged to aigles for this Post | |||
| Date | User | Comment | Amount |
| 07-18-2009 | littlejon | N/A | 500 |
|
||||
|
Thanks to both Ygor and Aigles. I went with Aigles' suggestion and it worked like a charm. Of course, I tweaked it to meet my needs. I was originally trying to use standard programming techniques to solve this problem. I am now officialy amazed at the power of sed and shell programming. Thank you, again! And, thanks to unix.com for the forum!
|
|
||||
|
Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|