LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-28-2005, 04:43 AM   #1
gmitra
LQ Newbie
 
Registered: Jun 2002
Location: Slovak Republic
Distribution: RedHat, Mandrake, Gentoo
Posts: 25

Rep: Reputation: 15
BASH: How to change a line in file?


Hello,
I need a simple script which changes one line in input file. Concretely, I want to replace the
title of eps file. The file before:
Code:
.
.
.
%%Title: Original name of the eps file
.
.
.
and after
Code:
.
.
.
%%Title: My new name of the eps file
.
.
.
has to be processed.
Thanks.
 
Old 01-28-2005, 05:03 AM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
sed 's/Original name of the eps file/My new name of the eps file/'

But somehow I suspect you're actually asking for more than that.
 
Old 01-28-2005, 05:47 AM   #3
gmitra
LQ Newbie
 
Registered: Jun 2002
Location: Slovak Republic
Distribution: RedHat, Mandrake, Gentoo
Posts: 25

Original Poster
Rep: Reputation: 15
Yes, actually for more. If you know how to put to the sed for replacement
value of variable, then it could be done e.g.:
[code]
NEW_TITLE="This is my new title"
OLD_TITLE=$(grep "%%Title:" $FILE | cut -d: -f2)
sed 's/$OLD_TITLE/$NEW_TITLE/' $FILE > output.eps
[\code]
But it doesn't work!
 
Old 01-28-2005, 05:59 AM   #4
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Would double quotes and an address work?

OLD=foo
NEW=bar
sed "/%%Title/s/$OLD/$NEW/" $FILE > out

-- I mean, I gather this file has other lines in it you *don't* want to change? Still kind of confused about the objective and restrictions here. But that may do what you want.

Last edited by slakmagik; 01-28-2005 at 06:01 AM.
 
Old 01-28-2005, 07:26 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
I suspect the sed solution can't work, as it choke on binary contents or very long lines which are likely to appear on an eps file.
 
  


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
bash shell script read file line by line. Darren[UoW] Programming 57 04-17-2016 06:07 PM
Bash - choose a random line from a file ericcarlson Linux - Software 27 11-12-2013 01:25 AM
bash: read a line from file zokik Linux - General 6 12-10-2008 09:24 AM
Read a line in a txt file with bash orgazmo Programming 5 05-03-2005 07:10 AM
Read a line in a txt file with bash orgazmo Linux - Newbie 3 05-03-2005 04:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:07 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