HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: sed help require
Operating System - Linux
        1839879
        Members
    
    
        3161
        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
11-22-2008 12:35 AM
11-22-2008 12:35 AM
			
				
					
					
						I want to replace the value of a variable  'TIMEZONE' with the other string, for that I tried to use 'sed', but no success, please help .
#!/bin/bash
CLOCK=/etc/sysconfig/clock
TIMEZONE=$(grep ^TIMEZONE $CLOCK)
if [ $TIMEZONE != TIMEZONE=\"Etc/GMT-5\" ]; then
cp $CLOCK /tmp/clock
cat /tmp/clock | sed 's/'$TIMEZONE'/TIMEZONE="Etc/GMT-5"/g' > $CLOCK
fi
# bash -x sedclock.sh
+ CLOCK=/etc/sysconfig/clock
++ grep '^TIMEZONE' /etc/sysconfig/clock
+ TIMEZONE='TIMEZONE="Etc/GMT-4"'
+ '[' 'TIMEZONE="Etc/GMT-4"' '!=' 'TIMEZONE="Etc/GMT-5"' ']'
+ cp /etc/sysconfig/clock /tmp/clock
+ cat /tmp/clock
+ sed 's/TIMEZONE="Etc/GMT-4"/TIMEZONE="Etc/GMT-5"/g'
sed: -e expression #1, char 24: unknown option to `s'
Regards
	
			
				
		
			
			
			
			
			
			
		
		
		
	
	
	
#!/bin/bash
CLOCK=/etc/sysconfig/clock
TIMEZONE=$(grep ^TIMEZONE $CLOCK)
if [ $TIMEZONE != TIMEZONE=\"Etc/GMT-5\" ]; then
cp $CLOCK /tmp/clock
cat /tmp/clock | sed 's/'$TIMEZONE'/TIMEZONE="Etc/GMT-5"/g' > $CLOCK
fi
# bash -x sedclock.sh
+ CLOCK=/etc/sysconfig/clock
++ grep '^TIMEZONE' /etc/sysconfig/clock
+ TIMEZONE='TIMEZONE="Etc/GMT-4"'
+ '[' 'TIMEZONE="Etc/GMT-4"' '!=' 'TIMEZONE="Etc/GMT-5"' ']'
+ cp /etc/sysconfig/clock /tmp/clock
+ cat /tmp/clock
+ sed 's/TIMEZONE="Etc/GMT-4"/TIMEZONE="Etc/GMT-5"/g'
sed: -e expression #1, char 24: unknown option to `s'
Regards
Solved! Go to Solution.
		2 REPLIES 2
	
	            
            
		
		
			
            
                - Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2008 01:15 AM
11-22-2008 01:15 AM
Solution
			
				
					
					
						Just looking, not trying anything, I'd say
that using "/" as the delimiter in your "sed"
"s" command is not a good idea when your
strings contain "/" characters. Something
like this might be closer:
sed -e 's|'$TIMEZONE'|TIMEZONE="Etc/GMT-5"|'
You really think that the "g" is needed?
		
		
	
	
	
that using "/" as the delimiter in your "sed"
"s" command is not a good idea when your
strings contain "/" characters. Something
like this might be closer:
sed -e 's|'$TIMEZONE'|TIMEZONE="Etc/GMT-5"|'
You really think that the "g" is needed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2008 03:51 AM
11-25-2008 03:51 AM
			
				
					
						
							Re: sed help require
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						Thanks for nice help Steven Schwada
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
		
		
	
	
	
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
