- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting problem
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
01-31-2005 08:04 PM
01-31-2005 08:04 PM
I have an issue with my script. I want to insert a line based on application of the server.I have a file called report1 as below :
#cat report1
sihp8012 /root/.rhosts bdhp4262 root
sihp8012 /root/.rhosts bdhp4262.na.pg.com root
sihp8012 /root/.rhosts sisn8001 root
sihp8012 /root/.rhosts sihp8026.ap.pg.com root
sihp8026 /root/.rhosts bdhp4337.na.pg.com root
sihp8026 /root/.rhosts 192.44.190.109 root
sihp8020 /root/.rhosts bdhp4337.na.pg.com root
and I have a file called appl that contains the application name :
#cat appl
oracle,sihp8012
sap,sihp8026
web,sihp8020
I want to insert the application name between field1 and field 2 of file report1, so the output will be as below :
sihp8012 oracle /root/.rhosts bdhp4262 root
sihp8012 oracle /root/.rhosts bdhp4262.na.pg.com root
sihp8012 oracle /root/.rhosts sisn8001 root
sihp8012 oracle /root/.rhosts sihp8026.ap.pg.com root
sihp8026 sap /root/.rhosts bdhp4337.na.pg.com root
sihp8026 sap /root/.rhosts 192.44.190.109 root
sihp8020 web /root/.rhosts bdhp4337.na.pg.com root
Anyone can help how to do using shell script? Pls help. High score will be given.
Thanks and Best Regards,
Dewa
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2005 08:40 PM
01-31-2005 08:40 PM
Solutionyou can try this rather simple script. Activate it with two parameters: $1=reportfile, $2=applcation_name:
#!/usr/bin/sh
GEM_IFS=$IFS
while read appl_name1 two three user_name1
do
IFS=","
while read user_name2 appl_name2
do
if [ "$appl_name1" = "$appl_name2" ]
then
echo "$appl_name1 $user_name2 $two $three $user_name1"
continue
fi
done <$2
IFS=$GEM_IFS
done <$1
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2005 08:42 PM
01-31-2005 08:42 PM
Re: Scripting problem
for node in `cat /tmp/appl$$|awk '{print $2}'`
do
appl=`grep $node /tmp/appl$$|cut -f1`
cat report |sed "s;$node;$node $appl;g" >> /tmp/output
done
rm /tmp/appl$$
I hv'nt tested it , the order of report may get changed..
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2005 09:38 PM
01-31-2005 09:38 PM
Re: Scripting problem
cat report1 | while read a b c d
do
echo "$a `grep $a appl | awk -F"," {'print $1'}` $b $c $d"
done
Have fun - Keith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2005 09:51 PM
01-31-2005 09:51 PM
Re: Scripting problem
this short one should work:
nawk 'BEGIN {FS=",";while (getline <"appl" == 1) ap[$2]=$1;FS=" "}
{if(ap[$1]) $1=$1" "ap[$1]; print}' report
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2005 10:12 PM
01-31-2005 10:12 PM
Re: Scripting problem
this is similar as kaps, but with little modified one...
#!/usr/bin/ksh
for name in `cat appl | awk -F"," {'print $2'}`
do
echo $name
appl=`grep $name appl| awk -F"," {'print $1'}`
echo $appl
cat report | grep ^$name |sed "s/$name/$name $appl/g" >> output
read
done
suresh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2005 10:31 PM
01-31-2005 10:31 PM
Re: Scripting problem
Thanks alot for your great help.
It should be fine now. I tested the script and it was working well.
Thanks again.
Best Regards,
Dewa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2005 10:34 PM
01-31-2005 10:34 PM
Re: Scripting problem
if you can change the format of appl to:
s/^sihp8012 /sihp8012 oracle /
s/^sihp8026 /sihp8026 sap /
s/^sihp8020 /sihp8020 web /
then you can use the command:
sed -f appl report1 > report2
Regards,
Pete