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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replacing a string in nth line maxmave Shell Programming and Scripting 1 06-04-2008 05:32 PM
replacing string in an XML file subin_bala Shell Programming and Scripting 2 06-03-2008 07:14 AM
using tab to finish command line parameter kymberm Shell Programming and Scripting 3 09-20-2002 03:54 PM
Command line parameter for C program Wing m. Cheng High Level Programming 3 05-18-2002 09:43 AM
Command Line width parameter Scoogie UNIX for Dummies Questions & Answers 2 02-08-2002 05:04 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-27-2006
chiru_h chiru_h is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 72
replacing a string in a file with command line parameter

Hello,
I am trying to replace a string with a paramter given along with the script.
I am replacing application1 to application2 with the script:
./change_app.sh application2

change_app.sh:
#!/bin/ksh
grep $1 applications.dat 2>&1 >/dev/null
echo $1
file=pckage.new
sed 's/Name: application1/Name: ${1}/g' "$file" > ./tmpfile
mv ./tmpfile "$file"

applications.dat has all the applications

But I get output as ${1} instead of application2. But when I echo $1, I get application2.
Please help in where I am going wrong, or if there is any better way.

Thanks
  #2 (permalink)  
Old 07-27-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
sed 's/Name: application1/Name: ${1}/g' "$file" > ./tmpfile

should be:

sed 's/Name: application1/Name: '${1}'/g' "$file" > ./tmpfile
  #3 (permalink)  
Old 07-27-2006
chiru_h chiru_h is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 72
Oops.. Thank you.
Quick question:
What do I have to do if I don't know the application1 name, but have to change - say a string next to Name: with application2.

sed 's/Name: application1/Name: '${1}'/g' "$file" > ./tmpfile

How do I refer application1 globally ?
  #4 (permalink)  
Old 07-28-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
You can do something like this (assume application name is alphanumeric) :
Code:
sed -e "s/Name: [[:alnum:]]\{1,\}/Name: ${1}/g" "$file" > ./tmpfile
Jean-Pierre.
  #5 (permalink)  
Old 08-02-2006
chiru_h chiru_h is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 72
I have a Version Name: 1.0.0_A0
I have to change to 1.1.0_A1
With the script
sed -e "s/Name: [[:alnum:]]\{1,\}/Name: ${1}/g" "$file" > ./tmpfile

The output I am getting is 1.1.0_A10.0_A0

I think its stopping when it sees '.'
Can you please tell me what do I need to do for special characters ??

Thanks
  #6 (permalink)  
Old 08-03-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
The following characters have been added : - . _
Code:
sed -e "s/Name: [-[:alnum:]._]\{1,\}/Name: ${1}/g" "$file" > ./tmpfile
The character - must be specified first.
Sponsored Links
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 08:37 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