- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk 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
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
07-30-2003 08:55 AM
07-30-2003 08:55 AM
Awk Question
002-345-067
Each point code will have three sections, each three numbers in length. Does anyone know of a good way in awk to remove the leading zeros of each of the fields so that the above point code would look like the following:
2-345-67
However I would want:
000-000-000
to be returned as:
0-0-0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2003 09:22 AM
07-30-2003 09:22 AM
Re: Awk Question
print it the way you want.
echo 002-345-067 | awk '{split($0, a, /-/); printf "%d-%d-%d\n", a[1], a[2], a[3]}'
2-345-67
echo 000-000-000 | awk '{split($0, a, /-/); printf "%d-%d-%d\n", a[1], a[2], a[3]}'
0-0-0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2003 09:26 AM
07-30-2003 09:26 AM
Re: Awk Question
use the printf statement
printf "%d","s","s","%d","%d", $1 "-" $2 "-" $3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2003 09:27 AM
07-30-2003 09:27 AM
Re: Awk Question
cat
HTH,
Michael.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2003 09:40 AM
07-30-2003 09:40 AM
Re: Awk Question
# sed -e 's/^/-/' -e 's/-0/-/g' -e 's/-0/-/g' -e 's/^-//' original_file > new_file
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2003 11:14 AM
07-30-2003 11:14 AM
Re: Awk Question
1-3-43253-22
pc03:/tmp/xx 508 $
or in your case, change all in file and replace file
# perl -pi -e's/(\d+)/$1+0/ge' infile
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2003 12:39 PM
07-30-2003 12:39 PM
Re: Awk Question
cat $file | awk '{FS="-"; printf("%d-%d-%d\n",$1,$2,$3)}' > $new_file
Nice and clean.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2003 01:57 AM
07-31-2003 01:57 AM
Re: Awk Question
$1 is your code
#!/bin/sh
typeset -i g1 g2 g3
echo $1 | tr "-" " " | read g1 g2 g3 && echo $g1"-"$g2"-"$g3
example : scriptname = filter
filter 002-345-067
2-345-67
filter 000-000-000
0-0-0
Rgds,
Jean-Luc