HPE GreenLake Administration
- Community Home
 - >
 - Servers and Operating Systems
 - >
 - Operating Systems
 - >
 - Operating System - HP-UX
 - >
 - Re: Need perl script for this test data
 
Operating System - HP-UX
        1840147
        Members
    
    
        3748
        Online
    
    
        110161
        Solutions
    
Forums
        Categories
Company
Local Language
                
                  
                  back
                
        
                
        
                
        
                
        
        
        
                
        
                
        
        
        
                
        
              
              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
                
                  
                  back
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
            
                
            
                
            
                
            
                
            
            
                
            
                
            
            
                
            
                
              
            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
Blogs
        Information
        Community
Resources
Community Language
        Language
        Forums
Blogs
Topic Options
			
				
					
	
			
		
	- 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-01-2008 06:27 PM
07-01-2008 06:27 PM
			
				
					
						
							Need perl script for this test data
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						sample 2 records: I have  million records like this
test data:
Name Measure1 Measure2 Measure3 Measure4
aaa 67 345 987
bbb 678 445 567 123
delimter ( ,)
I need to have perl script which reads input file from the user
Am intersted to do validation for Measure2 and Measure4 only
i need to pass one input file saying Pick Measure2 and Measure4
and do the validation for Measure2 Checking for Non zero values, if any row contains Non zero it needs to redirect to one file saying particular Name is having Measure value non zero.
one more validation if Measure4 contains the value greater than 500 then it also redirect to another file saying particular Name is having Measure value greater than 500 .
Output:
Measure2.txt file should show
Name Measure2
aaa
Measure4.txt file should show
Name Measure4
aaa 987
		
		
	
	
	
test data:
Name Measure1 Measure2 Measure3 Measure4
aaa 67 345 987
bbb 678 445 567 123
delimter ( ,)
I need to have perl script which reads input file from the user
Am intersted to do validation for Measure2 and Measure4 only
i need to pass one input file saying Pick Measure2 and Measure4
and do the validation for Measure2 Checking for Non zero values, if any row contains Non zero it needs to redirect to one file saying particular Name is having Measure value non zero.
one more validation if Measure4 contains the value greater than 500 then it also redirect to another file saying particular Name is having Measure value greater than 500 .
Output:
Measure2.txt file should show
Name Measure2
aaa
Measure4.txt file should show
Name Measure4
aaa 987
		2 REPLIES 2
	
	            
            
		
		
			
            
                - Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
07-01-2008 07:55 PM
07-01-2008 07:55 PM
			
				
					
						
							Re: Need perl script for this test data
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						You say the delimiter is a comma but the example has a space.  My script assumes space.
Also, I assume that the title isn't in the file?
(And the aaa line is missing a measure.)
I'm not sure why "bbb" isn't in your Measure2.txt file?
You can use two awk scripts to extract the data, if you don't care about two passes:
awk '
$2 > 0 {print $1}
' input-file > Measure2.txt
And the other:
awk '
$5 > 500 {print $1, $5}
' input-file > Measure4.txt
		
		
	
	
	
Also, I assume that the title isn't in the file?
(And the aaa line is missing a measure.)
I'm not sure why "bbb" isn't in your Measure2.txt file?
You can use two awk scripts to extract the data, if you don't care about two passes:
awk '
$2 > 0 {print $1}
' input-file > Measure2.txt
And the other:
awk '
$5 > 500 {print $1, $5}
' input-file > Measure4.txt
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
07-01-2008 08:46 PM
07-01-2008 08:46 PM
			
				
					
						
							Re: Need perl script for this test data
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						As Dennis wonders... where are the 'commas'?
Could this be the forum software eating tabs and spaces?
Could the missing but supposed 0 for the aaa line be expunged due to the presentation?
PLEASE ATTACH actual sample niput as a .TXT file next time?
Try this:
$ awk '!$2 {print $1 > "measure2.tmp"} $4>500 { print $1,$4 > "measure4.tmp" } ' x
$ cat measure2.tmp
a3a
a7a
$ cat measure4.tmp
b2b 567
b6b 567
$ cat x
a1a 1 67 345 987
b2b 678 445 567 123
a3a 0 67 345 87
b4b 678 445 67 123
a5a 1 67 345 987
b6b 678 445 567 123
a7a 0 67 345 87
b8b 678 445 67 123
Enjoy,
Hein.
ps... In perl...
$ perl -e 'open M2,">m2.tmp"; open M4,">m4.tmp"; while (<>) {@F=split; if (!@F[1]){print M2 "@F[0]\n"}; if (@F[3]>500){print M4 "@F[0] @F[3]\n"}}' x
$ cat m4.tmp
b2b 567
b6b 567
$ cat m2.tmp
a3a
a7a
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
		
		
	
	
	
Could this be the forum software eating tabs and spaces?
Could the missing but supposed 0 for the aaa line be expunged due to the presentation?
PLEASE ATTACH actual sample niput as a .TXT file next time?
Try this:
$ awk '!$2 {print $1 > "measure2.tmp"} $4>500 { print $1,$4 > "measure4.tmp" } ' x
$ cat measure2.tmp
a3a
a7a
$ cat measure4.tmp
b2b 567
b6b 567
$ cat x
a1a 1 67 345 987
b2b 678 445 567 123
a3a 0 67 345 87
b4b 678 445 67 123
a5a 1 67 345 987
b6b 678 445 567 123
a7a 0 67 345 87
b8b 678 445 67 123
Enjoy,
Hein.
ps... In perl...
$ perl -e 'open M2,">m2.tmp"; open M4,">m4.tmp"; while (<>) {@F=split; if (!@F[1]){print M2 "@F[0]\n"}; if (@F[3]>500){print M4 "@F[0] @F[3]\n"}}' x
$ cat m4.tmp
b2b 567
b6b 567
$ cat m2.tmp
a3a
a7a
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
		
	
	
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP