The UNIX and Linux Forums  


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
Search for multiple strings in specific position HugoH Shell Programming and Scripting 5 03-18-2009 11:56 AM
insert server name in position 1 on each line rlc198842 Shell Programming and Scripting 3 02-28-2009 10:06 PM
Deleting Characters at specific position in a line if the line is certain length Cailet Shell Programming and Scripting 10 12-17-2008 02:41 PM
Print lines with search string at specific position HealthyGuy Shell Programming and Scripting 4 12-04-2006 09:47 AM
how to insert line break + string in vi (search & replace ) umen Shell Programming and Scripting 1 06-08-2006 12:42 PM

 
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
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 03-20-2009
daikeyang daikeyang is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 24
search a line and insert string into specific at position

Hi, guys. I have one question:

How can I search for a line with certain string in it and then insert a string into this line?
For example:

There is a file called shadow, the contents of it are below:

**************************
...
yuanz:VIRADxMsadfDF/Q:0:0:50:7:::
sherrys:ASdfe#$DfdadfFAd:0:0:50:7:::
brownj:ADdfTRMnD$%3dfa:0:0:50:7:::
...
**************************

A variable called $user, another variable called $string. I want to search the line which has $user in it, and add $string at the beginning of the second column. If $user is brownj, and $string is STRING_, then the line will be:

brownj:STRING_ADdfTRMnD$%3dfa:0:0:50:7:::

I use the following code, but it doesn't work

sed 's/^$user:/$user:$string/' shadow

Can anybody help me with this?

Thank you very much for your time in advance

-Keyang
 

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 12:20 AM.


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