LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-10-2014, 06:21 PM   #1
tarangoyal
LQ Newbie
 
Registered: Dec 2014
Posts: 1

Rep: Reputation: Disabled
Exclamation Need to replace \ with / in a large file


I am unable to replace \ with / in a large file. I tried below parameter in vim and vi:
:%s/\/\//g

Can we create a custom script to replace any text including special character using for or while loops (inputs should be taken from the user for text, replacement needed and the file to work on)?
 
Old 12-10-2014, 06:26 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,150

Rep: Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887
Code:
[schneidz@hyper ~]$ cat tarangoyal.txt 
hello\world
l33t\h4x0rz
[schneidz@hyper ~]$ cat tarangoyal.txt | tr '\\' '/'
hello/world
l33t/h4x0rz
 
1 members found this post helpful.
Old 12-10-2014, 07:40 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,946

Rep: Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210
Quote:
Originally Posted by tarangoyal View Post
Can we create a custom script to replace any text including special character using for or while loops (inputs should be taken from the user for text, replacement needed and the file to work on)?
I would expect anything can be scripted.
Properly define your requirements, write the script(s), test, implement.
If you have problems, show us the script, the error, your attempts to resolve them, and maybe we can help.
 
Old 12-10-2014, 08:10 PM   #4
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,471

Rep: Reputation: 618Reputation: 618Reputation: 618Reputation: 618Reputation: 618Reputation: 618
Code:
sed -i 's@\@/@g' /path/to/file
The -i switch to sed replaces 'in place', if you want the results to go to a different file drop the -i and redirect ghe output with '>', the 'g' option" to the sed command means globally, ie replace-all.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sort large data in large file - commands smithy2010 Linux - Newbie 7 02-03-2013 10:01 AM
Shell Session Crashing when cat'ing a large file, tar'ing a large file, etc. newmanium2001 Linux - General 3 12-22-2012 11:32 PM
python: how do you replace unicode chars in large text files? BrianK Programming 1 12-19-2008 01:54 AM
[quick] trying to split a large file but linux says it's to large steve51184 Linux - General 16 05-06-2008 08:40 AM
Script file to replace large text blocks in files? stodge Linux - Software 0 09-27-2003 11:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration