The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace Junk chars (Sed) alfredo123 Shell Programming and Scripting 4 02-27-2008 03:38 PM
Using SED to get n chars after given value from file Kally UNIX for Dummies Questions & Answers 12 12-19-2007 01:54 AM
How to convert C source from 8bit chars to 16bit chars? siegfried Shell Programming and Scripting 0 09-26-2007 11:26 AM
cut last 4 chars pbsrinivas Shell Programming and Scripting 5 06-28-2007 09:14 PM
replace ascii chars without loosing it. braindrain Shell Programming and Scripting 4 02-01-2006 06:02 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-27-2007
Registered User
 

Join Date: Feb 2007
Posts: 5
replace chars,

Hi,

I want to replace the particular text in the middle of the line.
Ex. In the line 40-50 wanted to replace the char as 'x'
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-27-2007
dj -------
 

Join Date: Feb 2007
Location: Cochin/Bangalore, India
Posts: 380
If x="21312312dennis3123123123"
echo ${x/dennis/xxxxxx}
x will be 21312312xxxxxx3123123123 now

echo $x |sed 's/dennis/xxxxxx/' will also give the same result.

I hope this is what you are expecting!!
Reply With Quote
  #3 (permalink)  
Old 02-27-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,593
something like this,
to replace in between lines with a specific character,

Code:
>cat file
this is important
>awk ' sub( substr($0, 6, 2), "x", $0) ' file
thx is important
Reply With Quote
  #4 (permalink)  
Old 02-27-2007
Registered User
 

Join Date: Feb 2007
Posts: 5
Thanks.

Actually my doubt is :

Ex: abcdefesfe98765ksksksksk
i87838383akmsm3939398*

Now i want to replace the chars 10 - 15 position as X in this 2 lines.

Output shd be:
abcdefesfeXXXXXksksksksk
878383833XXXXX3939398*
Reply With Quote
  #5 (permalink)  
Old 02-27-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,593
modification to prev command,

Code:
awk ' sub( substr($0, 11, 5), "xxxxx", $0 )' file
Reply With Quote
  #6 (permalink)  
Old 02-27-2007
Registered User
 

Join Date: Feb 2007
Posts: 5
Thank you MM
Reply With Quote
  #7 (permalink)  
Old 02-28-2007
Registered User
 

Join Date: Dec 2006
Posts: 29
Try this if you have a very big file (say 100k records)

cut -c1-9 file > tempfile1
cut -c10-15 file | tr -cd "\n" "X" > tempfile2
cut -c15- file > tempfile3

paste -d"" tempfile1 tempfile2 tempfile3
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0