HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Sorting and extracting lines in a file
Operating System - HP-UX
        1839893
        Members
    
    
        3040
        Online
    
    
        110156
        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
	
		
			
            
                
            Go to solution
        
            
		
		
			
            	
	
		
        
		
	
	
		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
04-30-2003 04:43 AM
04-30-2003 04:43 AM
			
				
					
					
						Folks
A very quick one for someone i'm sure. I have a file which consists of lines such as
ldagtv20.log|E-AGTV-AUTH-DATE - '33002000'
ldagtv20.log|E-AGTV-AUTH-DATE - '33001999'
ldagtv20.log|E-AGTV-AUTH-DATE - '33001998'
ldagtv20.log|E-AGTV-AUTH-DATE - '33001997'
ldagtv20.log|E-AGTV-AUTH-DATE - '33001996'
ldagtv20.log|E-AGTV-AUTH-DATE - '32032002'
ldagtv26.log|E-AGTV-AUTH-DATE - '33002000'
ldagtv26.log|E-AGTV-AUTH-DATE - '33001999'
ldagtv26.log|E-AGTV-AUTH-DATE - '33001998'
ldagtv26.log|E-AGTV-AUTH-DATE - '33001997'
ldagtv26.log|E-AGTV-AUTH-DATE - '33001996'
ldagtv26.log|E-AGTV-AUTH-DATE - '32032002'
ldagtv30.log|E-AGTV-AUTH-DATE - '33002000'
ldagtv30.log|E-AGTV-AUTH-DATE - '33001999'
ldagtv30.log|E-AGTV-AUTH-DATE - '33001998'
ldagtv30.log|E-AGTV-AUTH-DATE - '33001997'
ldagtv30.log|E-AGTV-AUTH-DATE - '33001996'
ldagtv30.log|E-AGTV-AUTH-DATE - '32032002'
I would like to only bring back the first occurence of each log error e.g. ldagtv20.log|E-AGTV-AUTH-DATE - '33002000' but not any of the other ldagtv20.log|E-AGTV-AUTH-DATE lines .
Does anyone have any ideas on how to do this?
Any Help Appreciated
Michael
	
			
				
		
			
			
			
			
			
			
		
		
		
	
	
	
A very quick one for someone i'm sure. I have a file which consists of lines such as
ldagtv20.log|E-AGTV-AUTH-DATE - '33002000'
ldagtv20.log|E-AGTV-AUTH-DATE - '33001999'
ldagtv20.log|E-AGTV-AUTH-DATE - '33001998'
ldagtv20.log|E-AGTV-AUTH-DATE - '33001997'
ldagtv20.log|E-AGTV-AUTH-DATE - '33001996'
ldagtv20.log|E-AGTV-AUTH-DATE - '32032002'
ldagtv26.log|E-AGTV-AUTH-DATE - '33002000'
ldagtv26.log|E-AGTV-AUTH-DATE - '33001999'
ldagtv26.log|E-AGTV-AUTH-DATE - '33001998'
ldagtv26.log|E-AGTV-AUTH-DATE - '33001997'
ldagtv26.log|E-AGTV-AUTH-DATE - '33001996'
ldagtv26.log|E-AGTV-AUTH-DATE - '32032002'
ldagtv30.log|E-AGTV-AUTH-DATE - '33002000'
ldagtv30.log|E-AGTV-AUTH-DATE - '33001999'
ldagtv30.log|E-AGTV-AUTH-DATE - '33001998'
ldagtv30.log|E-AGTV-AUTH-DATE - '33001997'
ldagtv30.log|E-AGTV-AUTH-DATE - '33001996'
ldagtv30.log|E-AGTV-AUTH-DATE - '32032002'
I would like to only bring back the first occurence of each log error e.g. ldagtv20.log|E-AGTV-AUTH-DATE - '33002000' but not any of the other ldagtv20.log|E-AGTV-AUTH-DATE lines .
Does anyone have any ideas on how to do this?
Any Help Appreciated
Michael
Solved! Go to Solution.
		3 REPLIES 3
	
	            
            
		
		
			
            
                - Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2003 04:50 AM
04-30-2003 04:50 AM
Solution
			
				
					
					
						Hi Michael,
Using the 'sort' command I was able to get these results [I put your data in a file named sort.dat]:
>sort -t"|" -k 1,1 -u
ldagtv20.log|E-AGTV-AUTH-DATE - '32032002'
ldagtv26.log|E-AGTV-AUTH-DATE - '32032002'
ldagtv30.log|E-AGTV-AUTH-DATE - '32032002'
Is that what you had in mind?
JP
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
		
		
	
	
	
Using the 'sort' command I was able to get these results [I put your data in a file named sort.dat]:
>sort -t"|" -k 1,1 -u
ldagtv20.log|E-AGTV-AUTH-DATE - '32032002'
ldagtv26.log|E-AGTV-AUTH-DATE - '32032002'
ldagtv30.log|E-AGTV-AUTH-DATE - '32032002'
Is that what you had in mind?
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2003 04:55 AM
04-30-2003 04:55 AM
			
				
					
						
							Re: Sorting and extracting lines in a file
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						Something like:
cat file | while read FIRST DASH NUMBER
do
if [[ $FIRST != $LAST ]]
then
# new file
print $FIRST $DASH $NUMBER
LAST=$FIRST
else
continue #skip
fi
done
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
		
		
	
	
	
cat file | while read FIRST DASH NUMBER
do
if [[ $FIRST != $LAST ]]
then
# new file
print $FIRST $DASH $NUMBER
LAST=$FIRST
else
continue #skip
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2003 08:46 AM
05-01-2003 08:46 AM
			
				
					
						
							Re: Sorting and extracting lines in a file
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						Michael,
Try sort -u file > sort.file
Also, see the sort man pages.
Jack
		
		
	
	
	
Try sort -u file > sort.file
Also, see the sort man pages.
Jack
	i'm retired
			
			
				
			
			
			
			
			
			
		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
