Home Man
Search
Today's Posts
Register

If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

UNIX command to ignore replacing a search string if it is already present

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 10-17-2017
UNIX command to ignore replacing a search string if it is already present

Hello,

I am searching the following string Folder^ in a file and replacing it with Folder^/
However if the file already contains Folder^/ I want to avoid replacing it with Folder^//

To do this I have to do the following today:
1) echo "Folder^" | sed 's/Folder\^/Folder\^\//g'
I get "Folder^/"
2) echo "Folder^/" | sed 's/Folder\^/Folder\^\//g'
I get "Folder^//"

Is there a way in awk or sed to do this a single command. I know I can do the following - but I am looking for a more smarter way to do this
1) replace Folder^/ by Folder^
Code:
sed 's/FOLDER\^\//FOLDER\^/g'

2) replace Folder^ by Folder^/
Code:
sed 's/FOLDER\^/FOLDER\^\//g'


Last edited by RudiC; 10-17-2017 at 01:27 PM..
# 2  
Old 10-17-2017
Try
Code:
sed 's/Folder\^\/*/Folder\^\//g'

or e.g.
Code:
sed 's#Folder\^/*#Folder^/#g'

# 3  
Old 10-17-2017
Or
Code:
sed 's|\(Folder^\)/*|\1/|g'

Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search a string in a file which is also present in another file in UNIX raj028 Shell Programming and Scripting 6 07-22-2016 12:24 PM
String search in UNIX madhuraju Shell Programming and Scripting 3 05-13-2015 09:44 AM
Search, and add if present loba Shell Programming and Scripting 7 02-10-2014 02:11 AM
How write the ignore dupkey command in UNIX? punticci Shell Programming and Scripting 3 06-13-2013 09:31 AM
Search several string and convert into a single line for each search string using awk command AIX?. laknar Shell Programming and Scripting 5 12-09-2012 06:33 PM
grep exact string from files and write to filename when string present in file JC_1 Shell Programming and Scripting 4 08-06-2012 10:52 PM
Awk command for search a string in lspv khalidou13 Shell Programming and Scripting 8 09-24-2009 07:33 AM
Awk command for search a string in lspv khalidou13 Shell Programming and Scripting 1 09-23-2009 03:22 AM
Unix find command to print directory and search string princein UNIX for Dummies Questions & Answers 4 03-06-2007 07:46 AM
replacing a string in a file with command line parameter chiru_h Shell Programming and Scripting 5 08-03-2006 09:34 AM


All times are GMT -4. The time now is 06:57 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password