Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

find and replace command in one line using one command

UNIX for Dummies Questions & Answers


 
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 08-12-2005
vasikaran vasikaran is offline
Registered User
 
Join Date: Jun 2005
Last Activity: 19 December 2005, 7:38 AM EST
Location: india
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
find and replace command in one line using one command

Hi,

I have a entry in the file as

::BSNL GUJARAT::India::OUT::NAT::REWEL::POSTPAID::919426199995

if u see this, i have the delimiter as :: ,

all i want is to replace "::" as ":"

so how to do that..

pls help

thanks
Sponsored Links
    #2  
Old Unix and Linux 08-12-2005
vino's Unix or Linux Image
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 8 February 2016, 5:12 PM EST
Location: Sydney, Down Under
Posts: 2,848
Thanks: 0
Thanked 13 Times in 13 Posts

Code:
echo "::BSNL GUJARAT::India::OUT::NAT::REWEL::POSTPAID::919426199995" | sed -e 's#::#:#g'

Vino
Sponsored Links
    #3  
Old Unix and Linux 08-12-2005
reborg's Unix or Linux Image
reborg reborg is offline Forum Advisor  
Administrator Emeritus
 
Join Date: Mar 2005
Last Activity: 29 March 2012, 7:00 PM EDT
Location: Ireland
Posts: 4,464
Thanks: 0
Thanked 13 Times in 11 Posts
Since you want to make this change ':' cannot be a legal character in the fields and so this will also work.


Code:
echo "::BSNL GUJARAT::India::OUT::NAT::REWEL::POSTPAID::919426199995" | tr -s ':'

Be aware that this change will damage your data if ':' is a legal value, for example in a date.

Last edited by reborg; 08-12-2005 at 03:44 PM..
    #4  
Old Unix and Linux 09-04-2007
msubbums msubbums is offline
Registered User
 
Join Date: Feb 2006
Last Activity: 4 September 2007, 3:17 AM EDT
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Bug use perl

by perl u can do the following

perl -pi -e 's/::/:/g' <filename>

This replaces ur '::' to ':' in the file directly.
Sponsored Links
    #5  
Old Unix and Linux 08-20-2008
wip_vasikaran wip_vasikaran is offline
Registered User
 
Join Date: Jul 2006
Last Activity: 20 August 2008, 10:42 AM EDT
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
how to use sed command to find and replace a directory

i have a file.. which contains lot of paths ...

for eg.. file contains..

/usr/kk/rr/12345/1
/usr/kk/rr/12345/2
/usr/kk/rr/12345/3
/usr/kk/rr/12345/4
/usr/kk/rr/12345/5
/usr/kk/rr/12345/6
/usr/kk/rr/12345/7
/usr/kk/rr/12345/8

i want to replace /usr/kk/rr/12345/ with /usr/kk/yy/12555/

pls help
Sponsored Links
    #6  
Old Unix and Linux 08-20-2008
narayana123 narayana123 is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 20 August 2008, 4:53 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
$sed 's/::/:/g' source file>destination file
Sponsored Links
    #7  
Old Unix and Linux 08-20-2008
wip_vasikaran wip_vasikaran is offline
Registered User
 
Join Date: Jul 2006
Last Activity: 20 August 2008, 10:42 AM EDT
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
actually u have replied for my ealier posts.. pls refer above, i am trying to rename a directory...

i can do with normal texts.. but i am not able to rename the directories pls help
Sponsored Links
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find & Replace command - Fasta file Cevin21 UNIX for Dummies Questions & Answers 7 12-09-2011 12:54 AM
What is find and replace command in unix? rajkumar_g Shell Programming and Scripting 4 10-15-2010 05:48 PM
find and replace command prakash.gr Shell Programming and Scripting 1 12-07-2009 03:21 PM
Loop with sed command to replace line with sed command in it cbo0485 Shell Programming and Scripting 1 08-27-2009 11:19 AM
Sed command to find, manipulate and replace a number LT_2008 Shell Programming and Scripting 6 11-13-2008 10:28 AM



All times are GMT -4. The time now is 12:56 PM.