LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-17-2012, 02:05 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Rep: Reputation: 51
ASCII file. Replacing '[TEX]' with '$'.


Hi: I have an ascii file in which I want to replace all occurrences of the string [TEX] with the string $. How can I do it. Using vim with :s/old/new doesn't work in this case.
 
Old 04-17-2012, 02:14 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Assuming, from the single quotes, that you mean those both as literals.

You're going to need to escape some regex characters to do this. Example with sed(1):

Code:
$ echo 'foo [TEX] bar' | sed 's/\[TEX\]/\$/'
foo $ bar
 
Old 04-17-2012, 02:23 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Original Poster
Rep: Reputation: 51
I did
Code:
semoi@darkstar:~$ echo 'omni.txt [TEX] bar' | sed 's/\[TEX\]/\$/'
bash: $: command not found
where omni.txt is the file to modify, and got what you can see. What is bar?

Last edited by stf92; 04-17-2012 at 02:24 PM.
 
Old 04-17-2012, 03:26 PM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Original Poster
Rep: Reputation: 51
I had made a syntax error. I did this:
Code:
semoi@darkstar:~$ cat omni.txt | sed 's/\[TEX\]/\$/'
But only the first occurrence of the string in every line gets replaced.

Last edited by colucix; 04-17-2012 at 03:33 PM. Reason: fixed CODE tags
 
Old 04-17-2012, 03:34 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by stf92 View Post
I had made a syntax error. I did this:
Code:
semoi@darkstar:~$ cat omni.txt | sed 's/\[TEX\]/\$/'
But only the first occurrence of the string in every line gets replaced.
Try to add the g modifier to the s command:
Code:
sed 's/\[TEX\]/\$/g' omni.txt
An aside note: you don't need to use cat, since sed accepts file names as arguments.
 
Old 04-17-2012, 03:56 PM   #6
Nermal
Member
 
Registered: Jan 2009
Distribution: Debian
Posts: 59
Blog Entries: 2

Rep: Reputation: 6
in vim:

Code:
:%s/\[TEX\]/\$//g
 
Old 04-17-2012, 04:14 PM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by Nermal View Post
in vim:

Code:
:%s/\[TEX\]/\$//g
That is exactly what I did. Thanks. And thanks colucix.
 
  


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
vim file.tex !latex file.tex & pdfdvi file.dvi & xpdf -remote sname -reload Mol_Bolom Linux - General 0 07-09-2009 08:46 PM
Tex file viewer for windows ? Vilius Linux - Software 3 02-27-2009 11:46 AM
Ever used TeX, post your work. -- Tex Art Gallery barton Linux - Software 2 02-28-2006 03:29 AM
TeX can't find tex.fmt jrdioko Linux - Software 0 11-14-2005 06:34 PM
how to compile a tex-file ?? Lise Linux - Newbie 3 02-27-2005 01:20 PM


All times are GMT -5. The time now is 02:46 PM.

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