Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 08-06-2008, 09:20 AM   #1
Registered: Sep 2006
Posts: 73

Rep: Reputation: 15
how to replace value of to using shell script

helo ,

I have one requirement in my shell script. that
in my version.txt I have write down

Now I want to read this number and changes this number to and
store it in seperate variable. original file number need not be changed.

Old 08-06-2008, 09:49 AM   #2
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
If the original version number is stored in a variable, you can use substring replacement. For example
otherwise use sed, as in
new_version=$(echo | sed s/4[.]1[.]0[.]1[.]22/}
the square brackets around the dots in the pattern are character lists: this is a way to make sed interpret a literal dot, otherwise it has the special meaning of any single character and the strings 4c1.0d1.22 or 4.1e0.1922 match as well.

Last edited by colucix; 08-06-2008 at 09:50 AM.
Old 08-06-2008, 08:04 PM   #3
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
I think escaping "." with "\" is preferable and less confusing. It does require the statement to be in either '' or "", though.
Old 08-06-2008, 08:30 PM   #4
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
if you always know where you want to change
awk -F"." ' $4=0;$1=$1' OFS="." file


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
Need a script to search and replace text in file using shell script unixlearner Programming 14 06-21-2007 10:37 PM
Shell script: Find "\n\t..." to replace a string in a file michael24h7d Programming 8 05-11-2007 03:07 AM
Shell script to find/replace build new TAB record ljungers Programming 6 01-19-2007 04:47 PM
How can I use a shell script to add and replace lines in a file? abefroman Programming 10 12-27-2005 05:05 PM
Search and replace text in file using shell script? matthurne Linux - Software 2 11-02-2004 10:11 AM > Forums > Non-*NIX Forums > Programming

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

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