Sponsored Content
Top Forums UNIX for Beginners Questions & Answers UNIX command to ignore replacing a search string if it is already present Post 303005370 by mehimadri12 on Tuesday 17th of October 2017 12:59:56 PM
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 02:27 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replacing a string in a file with command line parameter

Hello, I am trying to replace a string with a paramter given along with the script. I am replacing application1 to application2 with the script: ./change_app.sh application2 change_app.sh: #!/bin/ksh grep $1 applications.dat 2>&1 >/dev/null echo $1 file=pckage.new sed 's/Name:... (5 Replies)
Discussion started by: chiru_h
5 Replies

2. UNIX for Dummies Questions & Answers

Unix find command to print directory and search string

Hi i need to print pathname in which the string present using 'find' command sample output like this Pathname String to be searched ---------- -------------------- /usr/test/myfile get /opt/test/somefile get Thanks in... (4 Replies)
Discussion started by: princein
4 Replies

3. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

4. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

5. Shell Programming and Scripting

How write the ignore dupkey command in UNIX?

I know that in oracle the is a way to write to ignore the dupkey, something like /*+ ignore_row_on_dupkey_index(tab, index_tab) */ Is there a way to do the same thing but with unix commands? I think there's a way with WHENEVER SQLERROR EXIT SQL.SQLCODE but i'm not sure and i don't know how do... (3 Replies)
Discussion started by: punticci
3 Replies

6. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

7. Shell Programming and Scripting

Search, and add if present

Dear All, I have to find a way to reorganize a table file according to the last column. The input file looks like this: cat Input1.txt: ID:12:23:00Q EU232 2342 234 123 231 aa1;ab2 ID:11:22:00E EU112 1232 211 112 233 ab2;ac3 ID:19:24:00S EU121 569 ... (7 Replies)
Discussion started by: loba
7 Replies

8. Shell Programming and Scripting

String search in UNIX

Hi Team, Please help me with a command which greps the exact match of the string which I am searching in a file. For examplecat > file abc abcd def ghi In the above file I just wanted to display abc which is first entry. When I execute grep command cat file | grep "abc" it results... (3 Replies)
Discussion started by: madhuraju
3 Replies

9. Shell Programming and Scripting

Search a string in a file which is also present in another file in UNIX

Hi there, I am new to Unix and had below requirement to finish my task. I have file1.dat which has data as shown below. case1.txt case2.txt case3.txt case4.txt file1.dat has only file names I have folder which has above files mentioned in file1.dat ./all_files case1.txt... (6 Replies)
Discussion started by: raj028
6 Replies

10. UNIX for Beginners Questions & Answers

Search partial string in a file and replace the string - UNIX

I have the below string which i need to compare with a file and replace this string in the file which matches closely. Can anyone help me on this. string(Scenario 1)- user::r--,user::ourfrd:r-- String(Scenario 2)- user::r-- File **** # file: /local/Desktop/myfile # owner: me # group:... (6 Replies)
Discussion started by: sarathy_a35
6 Replies
Mail::Filter(3) 					User Contributed Perl Documentation					   Mail::Filter(3)

NAME
Mail::Filter - Filter mail through multiple subroutines SYNOPSIS
use Mail::Filter; my $filter = Mail::Filter->new( &filter1, &filter2 ); my $mail = Mail::Internet->new( [<>] ); my $mail = $filter->filter($mail); my $folder = Mail::Folder->new( .... ); my $filter->filter($folder); DESCRIPTION
"Mail::Filter" provides an interface to filtering Email through multiple subroutines. "Mail::Filter" filters mail by calling each filter subroutine in turn. Each filter subroutine is called with two arguments, the first is the filter object and the second is the mail or folder object being filtered. The result from each filter sub is passed to the next filter as the mail object. If a filter subroutine returns undef, then "Mail::Filter" will abort and return immediately. The function returns the result from the last subroutine to operate on the mail object. METHODS
Constructors Mail::Filter->new([FILTER [, ... ]]) Create a new "Mail::Filter" object with the given filter subroutines. Each filter may be either a code reference or the name of a method to call on the <Mail::Filter> object. Accessors $obj->add(FILTER [, FILTER ...]) Add the given filters to the end of the filter list. Processing $obj->filter(MAIL-OBJECT | MAIL-FOLDER) If the first argument is a "Mail::Internet" object, then this object will be passed through the filter list. If the first argument is a "Mail::Folder" object, then each message in turn will be passed through the filter list. $obj->folder() While the "filter" method is called with a "Mail::Folder" object, these filter subroutines can call this method to obtain the folder object that is being processed. $obj->msgnum() If the "filter" method is called with a "Mail::Folder" object, then the filter subroutines may call this method to obtain the message number of the message that is being processed. SEE ALSO
This module is part of the MailTools distribution, http://perl.overmeer.net/mailtools/. AUTHORS
The MailTools bundle was developed by Graham Barr. Later, Mark Overmeer took over maintenance without commitment to further development. Mail::Cap by Gisle Aas <aas@oslonett.no>. Mail::Field::AddrList by Peter Orbaek <poe@cit.dk>. Mail::Mailer and Mail::Send by Tim Bunce <Tim.Bunce@ig.co.uk>. For other contributors see ChangeLog. LICENSE
Copyrights 1995-2000 Graham Barr <gbarr@pobox.com> and 2001-2007 Mark Overmeer <perl@overmeer.net>. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html perl v5.18.2 2014-01-05 Mail::Filter(3)
All times are GMT -4. The time now is 04:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy