Unix/Linux
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs Unix/Linux

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old August 1st, 2008, 07:19 AM
pk
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
preserving file permissions on search+replace

Friday 1 August 2008 00:01, Grant wrote:

Hi there,
>

I have a couple problems with a bash script on linux: a) not preserving
permissions, and b) overwriting a symlink (although I can avoid this by
using the symlink target).
>

script:
>

#!/bin/bash
#
[ $1 = "" ] && echo "Usage: $0 filename" && exit
>

tmp=$(mktemp) || exit
>

awk ' /search_term/ { sub(/search_term/, "replace_term") }
1' $1 $tmp && mv $tmp $1

Try with

cp "$1" "$tmp"
awk '' "$tmp" "$1"

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.

Reply With Quote
Reply

Viewing: Web Development Archives FAQs Unix/Linux > preserving file permissions on search+replace


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

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
Stay green...Green IT