- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- SED script to edit file in place
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2003 02:17 AM
тАО12-11-2003 02:17 AM
I'm looking for a script to run sed against a file and save the file as the same name.
I once had a utility that did this but I can't find it now.
I have about 1000 files that I need to edit and with this utility I could run it something like this:
sedutil s/arg1/arg2/g *
and it would run against all files and modify the ones that needed it and save them with the same file name.
Does anyone have something like this they could send me?
TIA
Sean
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2003 02:21 AM
тАО12-11-2003 02:21 AM
SolutionRead it carefully its extremely powerful.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2003 02:26 AM
тАО12-11-2003 02:26 AM
Re: SED script to edit file in place
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2003 02:32 AM
тАО12-11-2003 02:32 AM
Re: SED script to edit file in place
Also a simple one in shell :
#!/usr/bin/sh
SEDEXP="$1"
shift
TMP=/tmp/file$$
for FILE
do
sed "$SEDEXP" $FILE > $TMP
mv $TMP $FILE
done
Use it as :
$ sedutil "s/arg1/arg2/g" file1 file2 ...
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2003 02:47 AM
тАО12-11-2003 02:47 AM
Re: SED script to edit file in place
for f in *
do
sed "s/arg1/arg2/g" $f > F && mv F $f
done
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2003 03:01 AM
тАО12-11-2003 03:01 AM
Re: SED script to edit file in place
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2003 03:05 AM
тАО12-11-2003 03:05 AM
Re: SED script to edit file in place
# perl -pi -e's/arg1/arg2/g' file
in-place changes arg1 to arg2 (not checking on word bounds, so arg11 will be changed to arg21
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2003 03:13 AM
тАО12-11-2003 03:13 AM
Re: SED script to edit file in place
#!/usr/bin/sh
origDir=$(pwd)
SEDEXP="$1"
shift
TMP=/tmp/file$$
function fileops {
typeset FILE=$1
if [[ ! -r $file ]] ;then
print "$(pwd)/$file isn't readable"
return
fi
if [[ ! -w $file ]] ;then
print "$(pwd)/$file isn't writable"
return
fi
sed "$SEDEXP" $FILE > $TMP
mv $TMP $FILE
}
for arg in $@
do
if [[ -d $arg ]] ;then
cd $arg
for i in ls
do
if [[ -f $i ]] ;then
fileops $i
else
print "$(pwd)/$i isn't a regular file"
fi
done
cd $origDir
elif [[ -f $arg ]] ;then
fileops $arg
else
print "$arg isn't a directory or regualar file"
fi
done