POSTSCRIPT SUMMARY: Problem with sed - It misinterprets | (pipe).

From: LOEWENTHAL Simon <sloewenthal_at_gemini.edu>
Date: Tue May 31 2005 - 12:20:44 EDT
Update:  Here are the other suggestions:

nawk -F: '{print $1":*LK*:"$3":"$4":"$5":"$6":"$7":"$8":"$9}'
sed 's/^\([^:]*:\)[^:]*/\1*LK*/' shadow
sed 's/\([^:]*\):[^:]*:\(.*\)/\1:*LK*:\2/' /etc/shadow
TMP=`awk -F":" '{print $2}' /tmp/shadow.t` ; perl -pi -e s/${TMP}/*LK*/ /tmp/shadow.t
cat shadow.t | sed s/^\([^:]*\):\([^:]*\):\(.*\)$/\1:\*LK\*:\3/g > newshadow.t
sed 's/:[^:]*:/:\*LK\*:/' shadow.t > shadow.n

Thanks to John Julie ; Jesse Trucks l Christian Iseli ; Eric Horne ; 
Andrew Hall ; Julie Baumler ;  Chris Hoogendyk. 

I doublt that I'll ever get gsed -e 's/'`echo `cut -d: -f2 
shadow.t`|gsed -s 's/\//\\\//g'`'/\*LK\*/' working, which might be a 
good thing afterwall.

LOEWENTHAL Simon wrote:

>Hi everyone,
>
>Thank-you all for replying so quickly:
>As Elvio simply put it:
>
>awk -F":" '{printf("%s:*LK*:%s::::::\n",$1,$3)}' /etc/shadow
>While Luc said,
>
>	  egrep -v luc /etc/shadow > /tmp/shadow
>        echo 'luc:*LK*:::::::' >> /tmp/shadow
>        cp /tmp/shadow /etc/shadow
>        rm /tmp/shadow
>        chmod 400 /etc/shadow
>
>For info, I tried using an @ instead of a /, but got the same result,
> gsed -e 's@'`echo `cut -d: -f2 shadow.t`|gsed -s 's@\/@\\\/@g'`'@\*LK\*@' <shadow.t shadow.n 
>./test: syntax error at line 1: `|' unexpected
>
>Awk wins this time.  
>I'd still like to know the sed solution, though.
>
>Many thanks to you all,
>S.
>
>
>LOEWENTHAL Simon wrote:
>
>  
>
>>Dear all Sed madmen,
>>
>>I'm trying to write something that sets the encrypted field in the 
>>shadow file to *LK*, but sed will choke whenever the field has a / in 
>>it, so I wrote something to nest sed inside sed with cut so that it 
>>replaces instances of / with /\
>>
>>However, sed chokes when interpreting the |.  I have tried putting ' 
>>and ` in all the places I can think of, but it usually makes it worse.
>>
>>Cut the encrypted password out and then get gsed to replace the / with 
>>\, which work fine.
>>
>>Cat shadow.t
>>
>>   GogunE:ndY3rmE/bkxt.:12180::::::
>>
>>   echo `cut -d: -f2 shadow.t`|gsed -s 's/\//\\\//g'
>>
>>What it correctly produces,
>>
>>   ndY3rmE\/bkxt.
>>
>>Finally I use gsed to replace the earlier output with *LK*.
>>
>>    gsed -e 's/'`echo `cut -d: -f2 shadow.t`|gsed -s 
>>'s/\//\\\//g'`'/\*LK\*/' <shadow.t
>>
>>Then it chokes,
>>
>>   ./test: syntax error at line 1: `|' unexpected
>>
>>Regards, S.
>>
>>PS. I'm sorry that this is not Sun specific, but I think that there 
>>are plenty of sed users in the audience, but I've been at this for the 
>>past 5 hours and am starting to doubt my sanity.
>>
>>    
>>
>
>  
>

-- 

ISG/Gemini/AURA
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Tue May 31 12:21:52 2005

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:47 EST