LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 01:05 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
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, 01: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, 01:23 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
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 01:24 PM.
 
Old 04-17-2012, 02:26 PM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
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 02:33 PM. Reason: fixed CODE tags
 
Old 04-17-2012, 02:34 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 02: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, 03:14 PM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

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

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


Reply



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 07:46 PM
Tex file viewer for windows ? Vilius Linux - Software 3 02-27-2009 10:46 AM
Ever used TeX, post your work. -- Tex Art Gallery barton Linux - Software 2 02-28-2006 02:29 AM
TeX can't find tex.fmt jrdioko Linux - Software 0 11-14-2005 05:34 PM
how to compile a tex-file ?? Lise Linux - Newbie 3 02-27-2005 12:20 PM

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

All times are GMT -5. The time now is 10:17 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
Open Source Consulting | Domain Registration