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
Replace Entire line if any part matches regexp Cocoabean Shell Programming and Scripting 6 09-14-2008 03:02 PM
replace part of single string in a file nixjennings UNIX for Dummies Questions & Answers 2 08-06-2008 09:47 PM
regarding replace a part of a string madhu_aqua14 UNIX for Dummies Questions & Answers 7 08-04-2008 10:07 AM
Find and replace a part of the word in Shell mihirk Shell Programming and Scripting 3 06-25-2007 03:08 AM
using sed to replace a part of string csejl Shell Programming and Scripting 6 01-12-2004 11:48 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 11-21-2008
alirezan alirezan is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 22
Replace part of a line with sed/awk

Hello

I have a document and in this document I have several occurrence of "VAR == xxxxxxx" and xxxxx can be anything. I don't know what it is. I want to replace the 'xxxxx's with something I know.

What I know however, is the line numbers of the VAR =='s in the file.

How can I replace the xxxx's with awk or sed? Can someone please help me out here?

Thanks
Ali
  #2 (permalink)  
Old 11-21-2008
replytoshishir replytoshishir is offline
Registered User
  
 

Join Date: May 2006
Location: Bangalore
Posts: 23
re: Replace part of a line with sed/awk

i tried to simulate your scenario.. so created an input file as below by the name inputfile.txt
-------------
var1=shishir
var2=shishir
var1=shishir
var2=shishir
var3=shishir
------------
the sed script to replace the "shishir" with "srivastava" in "var1=shishir" at line#3 is as follows

sed '3 s/var1=[a-z][a-z]*/var1=srivastava/'

and the output is as follows:
-------------
var1=shishir
var2=shishir
var1=srivastava
var2=shishir
var3=shishir
------------


I think this is what you were looking at..

thnx
Shishir srivastava
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 01:51 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