- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- remove zero from values
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
тАО03-14-2008 01:50 AM
тАО03-14-2008 01:50 AM
I have one file(myfile.txt) that contains values like:
"575129","0.2x0.4","0001","2"
"575129","0.2x0.4","0002","2"
"575129","0.4x0.3","0003","2"
"575129","0.4x0.3","0004","2"
"575129","0.3x0.4","0005","2"
i am trying to group values from Field 3 e.g "0002" ....
CODE i am using is :
a=`grep "575129" myfile.txt | cut -f6 -d'"'`
surface=`echo $a | awk '{out=$1;for (k=2;k<=NF;k++){out=sprintf("%s,%s",out,$k);}print out}'`
value of surface will be: 00001,00002 ...
i do not want to take 0's means only 1,2,3 ...
Can some one please help me in this regard.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2008 02:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2008 02:20 AM
тАО03-14-2008 02:20 AM
Re: remove zero from values
If I understand you correctly, you
want a simple result like 1,2,3,4,5,
Many ways to achieve this. One of them
is by using two standard Shell tools:
sed -e 's/"//g' myfile.txt | awk -F"," '/575129/ {printf("%d,", $3)}'
Cheers,
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2008 02:35 AM
тАО03-14-2008 02:35 AM
Re: remove zero from values
Brilliant. Shows thoughtful testing.
dyi # surface='00100'
dyi # echo $surface | sed 's/0//g'
1
I'm sure that that's what he wants.
Perhaps you meant something more like this?
echo $surface | sed 's/^0*//'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2008 03:28 AM
тАО03-14-2008 03:28 AM
Re: remove zero from values
Your reply solved my problem.
Thanks to all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2008 03:29 AM
тАО03-14-2008 03:29 AM
Re: remove zero from values
but you u follow above expert advise of my friend after looking all aspects you will again a looser.
echo $surface
0001,0002,0003,0004,00050
echo $surface | sed 's/^0*//'
1,0002,0003,0004,00050
the more generic code will be
echo $surface|sed 's/^0*//g'|sed 's/,0*/,/g'
cheers,
Awadhesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2008 03:29 AM
тАО03-14-2008 03:29 AM
Re: remove zero from values
Thanks a lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2008 03:33 AM
тАО03-14-2008 03:33 AM
Re: remove zero from values
a=`grep "575129" myfile.txt | cut -f6 -d'"'`
surface=`echo $a | awk '{out=$1;for (k=2;k<=NF;k++){out=sprintf("%s,%s",out,$k);}print out}'`
can do some testing also and can remove bugs also if it is there in any forum members reply.
:)
Regards,
Awadhesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2008 04:24 AM
тАО03-14-2008 04:24 AM