- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sed or awk examples
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-18-2001 10:27 AM
тАО10-18-2001 10:27 AM
Web site, white paper, manual, or real case from yourself are all welcome. Thank you so much in advance.
Shawn
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2001 10:34 AM
тАО10-18-2001 10:34 AM
Solution- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2001 10:36 AM
тАО10-18-2001 10:36 AM
Re: sed or awk examples
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2001 10:38 AM
тАО10-18-2001 10:38 AM
Re: sed or awk examples
10 points is ready for everybody.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2001 10:49 AM
тАО10-18-2001 10:49 AM
Re: sed or awk examples
There is also a 'sed & awk' Pocket Reference by Arnold Robbins publiched by O'Reilly. ISBN - 1-56592-729-X
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2001 11:24 AM
тАО10-18-2001 11:24 AM
Re: sed or awk examples
I too suggest that you get the O'reilly book 'Sed and Awk'. I think I'll just attach one of my scripts that does 2 things - along with a few comments.
This script is actually a shell script which builds awk scripts 'on the fly' and then in turn invokes the scripts. It also has traps to remove the temporary scripts upon program exit.
The math in this awk is fairly intense but what it does is to convert a calendar date into a 'Julian Day' - essentially the number of days since 4000 years ago. It is used by astronomers to make calculations easy. Real Julian Days are actually floating point values and the days begin at noon UTC so that midnite is really Julian Day + 0.5. This version, which is much more useful in the computer world uses integer arithmetic and start at midnite. It can also do the reverse calculation, so if you want to know what the date will be exactly 167 days from now, it's very easy.
I'm just including this as an example of a fairly complex awk program being invoked by a shell script. One thing that is not often mentioned in awk documentation is how to declare local variables in a function. To a programming purist, awk's method is very hokey but it does work.
function silly(s1,s2, i,j,s_out)
{
i = 10
j = 2 + i
s_out = sprintf("%s%s%d",s1,s2,j)
printf("%s\n",s_out)
return(j)
}
The main awk program which calls the function might do this:
cc = silly("String1",String2")
Note that the function has 5 formal arguments but only 2 actual arguments. The remaining 3 args become local variables to the function and thus that instance of i,j, and s_out will not conflict with the use of other variables with the same name; either in other functions or within the main awk body.
Another point I would make is to first develop complicated scripts as a file and use the awk -f myfile.awk method to run awk. The awk '{print $1}' method is fine for one-liners but gets very tricky when the script becomes a bit more complex.
Another fairly useful trick is to use more then one -f argument. You can supply multiple -f arguments and that becomes a method for including commonly used functions which are then combined to produce a complex program. If you have several complex awk functions, they can then be centrally located and changed in one place rather than having to hunt them in a ton of awk scripts.
One other point that I would make: I've been doing awk/sed for quite a few years but now I find myself writing more and more perl. If I were going to learn from scratch now, I would skip awk and sed and just use perl. I'm not putting awk and sed down, it's just that perl can do anything those guys can do and do it in a cross-platform environment. For example, it's very easy to set up bidrectional sockets between a UNIX box and an NT server using perl.
Food for thought, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2001 11:26 AM
тАО10-18-2001 11:26 AM
Re: sed or awk examples
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2001 11:29 AM
тАО10-18-2001 11:29 AM
Re: sed or awk examples
Sorry to trouble you.
For progs.tar.gz, I donot know how to uncompress it, tar -xvf don't work.
For eap3.tar, I don't know how to read it on Unix, they are .xml.
Or, even you have better way so that I can read all of those files on Win NT?
Your reply is really appreciate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2001 11:38 AM
тАО10-18-2001 11:38 AM
Re: sed or awk examples
Just use gunzip which is usually located in /usr/contrib/bin
gunzip /tmp/myfile.tar.gz
which will unzip to /tmp/myfile.tar
you then tar xvf /tmp/myfile.tar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2001 11:49 AM
тАО10-18-2001 11:49 AM
Re: sed or awk examples
Here's one for 'sed' that I like (and has been around in a few places):
http://www.student.northpark.edu/pemente/sed/sed1line.txt
Regards!
...JRF...