- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: 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
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?