nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

To find and replace in text file

This is a discussion on To find and replace in text file within the Shell scripting forums, part of the Development/Scripting category; Hi, I need help on following problem. I have a text file something like below... I have to replace ":" ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 11-14-2007, 10:27 PM
Junior Member
User
 
Join Date: Nov 2007
My distro: RedHat
Posts: 2
Rep Power: 0
nashtech is on a distinguished road
Default To find and replace in text file

Hi,

I need help on following problem.

I have a text file something like below...

I have to replace ":" "." "space" with , using either sed or awk can some one help me on this...

Thanks in Advance..

=====================================

21:2007.11.13 00:38:13:399 Env/TP-Processor8:INFO:CORE BEGIN Session=9C3ACA5E8BE596EC39D2761AC66EC9E2.bstby1 Active Sessions: 776
29:2007.11.13 00:38:13:918 Env/TP-Processor6:INFO:CORE BEGIN Session=3152E297D96912192109B8F9BEBB1446.bstby1 Active Sessions: 777
88:2007.11.13 00:38:15:832 Env/TP-Processor2:INFO:CORE BEGIN Session=50D731F3EE59D3595A25140F166E9F93.bstby1 Active Sessions: 767
116:2007.11.13 00:38:16:793 Env/TP-Processor7:INFO:CORE BEGIN Session=B7977F67D06591A78AA2F290DBCE6F2C.bstby1 Active Sessions: 768
144:2007.11.13 00:38:19:219 Env/TP-Processor12:INFO:CORE BEGIN Session=19C3468F71BC6B2BEA03C3F2D4F74E44.bstby1 Active Sessions: 769
172:2007.11.13 00:38:21:930 Env/TP-Processor2:INFO:CORE BEGIN Session=13DA23B1E5787E4E07B3098A17CAFBAC.bstby1 Active Sessions: 770


=============================================
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-15-2007, 10:19 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Code:
echo '21:2007.11.13 00:38:13:399 Env/TP-Processor8:INFO:CORE BEGIN Session=9C3ACA5E8BE596EC39D2761AC66EC9E2.bstby1 Active Sessions: 776' | sed -e "s/:/./g"
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #3 (permalink)  
Old 11-15-2007, 10:57 PM
Junior Member
User
 
Join Date: Nov 2007
My distro: RedHat
Posts: 2
Rep Power: 0
nashtech is on a distinguished road
Default

Thanks a lot Vivek... It worked perfectly
Reply With Quote
  #4 (permalink)  
Old 07-31-2008, 07:46 PM
Junior Member
User
 
Join Date: Jul 2008
My distro: Debian
Posts: 3
Rep Power: 0
pooppp is on a distinguished road
Default i got the below answer but if i m hving tht txt in file..where to mention my filename

i got the below answer but if i m hving tht txt in file..where is the place int the script to mention my filename sam.txt
sam.txt contains
21:2007.11.13 00:38:13:399 Env/TP-Processor8:INFO:CORE BEGIN Session=9C3ACA5E8BE596EC39D2761AC66EC9E2.bstby1 Active Sessions: 776
29:2007.11.13 00:38:13:918 Env/TP-Processor6:INFO:CORE BEGIN Session=3152E297D96912192109B8F9BEBB1446.bstby1 Active Sessions: 777
88:2007.11.13 00:38:15:832 Env/TP-Processor2:INFO:CORE BEGIN Session=50D731F3EE59D3595A25140F166E9F93.bstby1 Active Sessions: 767
116:2007.11.13 00:38:16:793 Env/TP-Processor7:INFO:CORE BEGIN Session=B7977F67D06591A78AA2F290DBCE6F2C.bstby1 Active Sessions: 768
144:2007.11.13 00:38:19:219 Env/TP-Processor12:INFO:CORE BEGIN Session=19C3468F71BC6B2BEA03C3F2D4F74E44.bstby1 Active Sessions: 769
172:2007.11.13 00:38:21:930 Env/TP-Processor2:INFO:CORE BEGIN Session=13DA23B1E5787E4E07B3098A17CAFBAC.bstby1 Active Sessions: 770


Quote:
Originally Posted by nashtech View Post
Hi,

I need help on following problem.

I have a text file something like below...

I have to replace ":" "." "space" with , using either sed or awk can some one help me on this...

Thanks in Advance..

=====================================

21:2007.11.13 00:38:13:399 Env/TP-Processor8:INFO:CORE BEGIN Session=9C3ACA5E8BE596EC39D2761AC66EC9E2.bstby1 Active Sessions: 776
29:2007.11.13 00:38:13:918 Env/TP-Processor6:INFO:CORE BEGIN Session=3152E297D96912192109B8F9BEBB1446.bstby1 Active Sessions: 777
88:2007.11.13 00:38:15:832 Env/TP-Processor2:INFO:CORE BEGIN Session=50D731F3EE59D3595A25140F166E9F93.bstby1 Active Sessions: 767
116:2007.11.13 00:38:16:793 Env/TP-Processor7:INFO:CORE BEGIN Session=B7977F67D06591A78AA2F290DBCE6F2C.bstby1 Active Sessions: 768
144:2007.11.13 00:38:19:219 Env/TP-Processor12:INFO:CORE BEGIN Session=19C3468F71BC6B2BEA03C3F2D4F74E44.bstby1 Active Sessions: 769
172:2007.11.13 00:38:21:930 Env/TP-Processor2:INFO:CORE BEGIN Session=13DA23B1E5787E4E07B3098A17CAFBAC.bstby1 Active Sessions: 770

=============================================
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Cups is not printing text file with proper format, staircasing issue Ashish Pathak CentOS / RHEL / Fedora 1 11-18-2007 09:12 AM
can not find the username in /etc/passwd file subrata1in Getting started tutorials 5 03-27-2007 12:45 PM
can not find user name in /etc/passwd file subrata1in Linux software 2 03-26-2007 11:44 AM
rearranging columns in a text file sureshbup Shell scripting 2 12-06-2006 10:43 AM
Replacing text in a file using awk postyrus Shell scripting 4 05-02-2005 04:31 PM


All times are GMT +5.5. The time now is 05:57 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36