- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting question
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
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
тАО10-30-2009 06:30 AM - last edited on тАО11-26-2012 06:57 PM by Maiko-I
тАО10-30-2009 06:30 AM - last edited on тАО11-26-2012 06:57 PM by Maiko-I
Hi All, I am attempting to search a file for all occurances of "PP= 2" the number may differ. What I want to do is search for the "PP=" part and any number assigned to PP to be either multiplied or divded. I would then like to save the entire file and not just the lines with PP=, with the new settings.
I could do this using awk as in:
awk '/PP=/{print $1" "$2 *2}' filename > file1
but I need the whole contents of the file and not just the lines containing PP=.
Any Ideas Appreciated.
cheers
Martin
P.S. this thread has been moved from HP-UX > System Administration to HP-UX > languages - HP Forums Moderator
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2009 08:41 AM
тАО10-30-2009 08:41 AM
Re: Scripting question
grep -v "PP\=" file > non_PP_lines_file
grep "PP\=" file > PP_lines_file
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2009 08:51 AM
тАО10-30-2009 08:51 AM
Re: Scripting question
then
echo "Yep, it PP= is in this file"
#(substitute above with any action youwish)
else
echo "Nope, PP= is not in this file"
#(ditto)
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2009 08:53 AM
тАО10-30-2009 08:53 AM
Re: Scripting question
PP=[:digit:]
to
PP=[:digit:] * 2.
while retaining the entirety of the file....I'd guess he needs to keep the order of lines within that file as well, but a better problem description (or sample input with desired output) is needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2009 10:06 AM
тАО10-30-2009 10:06 AM
Re: Scripting question
your right I need to keep the integrity of the file, I have used sed to amend all the other entries, the issue I have is I need to either multiply or divide the number assoiciated with PP= while keeping the rest of the file intact. I could use awk but that strips the rest of the file. and I dont believe you can use mathamatical options in sed? saying that I am not a sed expert, but I dont think so. If awk has an option to show the whole file while manipulating the figure then that would be my solution, but again I dont believe it does.?
Any ideas cause I'm stumped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2009 10:11 AM
тАО10-30-2009 10:11 AM
Re: Scripting question
grep "PP\=" file > PP_lines_file
cat PP_lines_file | sed 's/\=/ /' | awk ${print $1 $2) ) | while read a b
do
TOT=$(($b+$TOT))
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2009 10:23 AM
тАО10-30-2009 10:23 AM
Re: Scripting question
the awk part was'nt right, but did look promising, I have tried to amend but still not working, could it the the ksh I am using?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2009 11:20 AM
тАО10-30-2009 11:20 AM
Re: Scripting question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2009 11:50 AM
тАО10-30-2009 11:50 AM
Re: Scripting question
PP=2 and replace it w/ PP=4?
PP=3 and replace it w/ PP=6?
and not something like:
PP=2*2 or PP=3*2 (which is how I read the original post.
awk will by default read and process every line, in your example you tell it to pattern match, then process
a script like the following might be a start
{
if ( $1 ~ /PP=/ )
{
x=split($1,ppline,"=")
print ppline[1] "=" ppline[2]*2
}
else
print $0
}
~
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2009 01:03 PM
тАО10-30-2009 01:03 PM
Re: Scripting question
You refuse to award points even to get the final answer of your script problem.
So I went back and check you out, 1 point assigned for 11 questions asked.
Sigh. You know this forum is going Paid in Advanced because of people like you?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2009 11:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-31-2009 01:19 AM
тАО10-31-2009 01:19 AM
Re: Scripting question
Check this out:
Code:
--------------------------------------------
# awk '{$2=$2*2} /PP=/ {print $0}' pp_file
--------------------------------------------
# cat pp_file
PP= 2 As a quick 0909 A00990
PP= 3 As a quick A09093 2342
PP= 5 sas a quick 09000! A00
PP= 9 sa a aqij 0900 A009
PP= 6 as oks fA09000 0090 00
SP= 7 sk sa aik a0000 aa
PP= 8.1 Asa sfllks 9990
NP= 3 aksfs A0009 aa0009
#
# awk '{$2=$2*2} /PP=/ {print $0}' pp_file
PP= 4 As a quick 0909 A00990
PP= 6 As a quick A09093 2342
PP= 10 sas a quick 09000! A00
PP= 18 sa a aqij 0900 A009
PP= 12 as oks fA09000 0090 00
PP= 16.2 Asa sfllks 9990
#
Cheers,
Raj.
*Remember to assign points to the responses all who tried o help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2009 02:36 PM
тАО11-01-2009 02:36 PM
Re: Scripting question
If you satisfied with the answer and your problem got solved then please make a habit to assign points,
Those people who give there valuable time for your problem they should expect some apparition from you in terms of points.
To know how to assign points please go through the below link
http://forums13.itrc.hp.com/service/forums/helptips.do?admit=109447627+1256027208667+28353475#33
Thanks
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2009 11:25 PM
тАО11-01-2009 11:25 PM
Re: Scripting question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2009 11:28 PM
тАО11-01-2009 11:28 PM
Re: Scripting question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2009 11:28 PM
тАО11-01-2009 11:28 PM
Re: Scripting question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2009 11:38 PM
тАО11-01-2009 11:38 PM
Re: Scripting question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-02-2009 01:38 AM
тАО11-02-2009 01:38 AM
Re: Scripting question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-02-2009 07:31 AM
тАО11-02-2009 07:31 AM
Re: Scripting question
Let me take a different approach since its easy to miss some of these links in your profile. Here is your profile
http://forums11.itrc.hp.com/service/forums/publicProfile.do?forumId=1&userId=CA828944
At the very bottom under the last section titled "My Questions" is a hard to miss link call "unassigned points", every thread where you haven't provided 0 to 10 points still gets flagged. And the only way you can remove these flags is by assigning points.