The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Split a file based on pattern in awk, grep, sed or perl kumarn Shell Programming and Scripting 5 06-20-2008 10:51 AM
selecting only few lines from many based on a common pattern damansingh Shell Programming and Scripting 2 05-28-2008 06:29 AM
replace character in a string pattern and save the change in same file mihir0011 Shell Programming and Scripting 2 09-26-2007 05:31 PM
search file, change existing value based on input (awk help) nortonloaf Shell Programming and Scripting 3 12-06-2006 01:35 AM
appending with sed based on matched pattern jack1981 Shell Programming and Scripting 2 07-20-2006 06:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-19-2008
orbeyen orbeyen is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 5
Red face how to change a particular value in a file based on a pattern

how to change a particular value in a line of a file based on a pattern

eg:

source file will be like
=================

99999999999 maximum number(0)
ksuisikjjsl;;l skjss''llsl
minimum number 0000000
maximum number of golds(0)


target should be like
=================

99999999999 maximum number(1)
ksuisikjjsl;;l skjss''llsl
minimum number 0000000
maximum number of golds(1)

the pattern i searched ihere is maximum, once i find the pattern the value which is (1) needs to change to (2).

i will give command line parameters for the pattern needs to be searched and the existing value and the value which it needs to be changed.

in the above example

Pattern to search is maximum
existing value is 1
value to be replaced is 2.

Note : the open and closed braces will be there in all the lines < (1) >.
  #2 (permalink)  
Old 08-19-2008
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,574
1rst solution:
with vi:
edit the file with vi then
:%s/(1)/(2)
  #3 (permalink)  
Old 08-19-2008
orbeyen orbeyen is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 5
clarifications

The requirement needs to be done in run time.

Note : I have a previous task after the completion of the task the script needs to be kicked off and the changes needs to be made in the file.

and also the reqt is < changing a particular value in a line of a file based on a pattern >
  #4 (permalink)  
Old 08-19-2008
orbeyen orbeyen is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 5
i would like to quickly clarify the reqt once again

eg:

source file will be like
=================

99999999999 maximum number(0)
ksuisikjjsl;;l skjss''llsl(0)
minimum number 0000000(0)
maximum number of golds(0)


target should be like
=================

99999999999 maximum number(1)
ksuisikjjsl;;l skjss''llsl(0)
minimum number 0000000(0)
maximum number of golds(1)
  #5 (permalink)  
Old 08-19-2008
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,574
Well, that means do the same with sed...
  #6 (permalink)  
Old 08-19-2008
orbeyen orbeyen is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 5
Can you please guide me, with the same
  #7 (permalink)  
Old 08-19-2008
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,574
Asume your file is called gigi
then:
cat gigi|while read line
do
OK=$(echo $line|grep maximum)
if [ "$OK" = "" ]
then
echo $line >>gigi.out
else
echo $OK | sed -e 's/(1)/(2)/'>>gigi.out
fi
done

#
then
mv gigi.out>gigi
I believe ther is no simple solution because you are looking for a pattern to do something else (modify the end of line...)
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0