- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Inline "Sed" script
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
Forums
Discussions
Discussions
Discussions
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
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-15-2004 05:12 AM
12-15-2004 05:12 AM
Inline "Sed" script
Years ago I had a script that essentially did inline sed on files.
With it you'd call the script and give the sed command, it would then run against the file(s) you specify and do the sed and save the file.
Does anyone have something like this that they'd be willing to post?
TIA.
Sean
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2004 05:17 AM
12-15-2004 05:17 AM
Re: Inline "Sed" script
Is this what you are looking for.
sed one-liner
http://www.student.northpark.edu/pemente/sed/sed1line.txt
Hope this helps.
Regds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2004 05:19 AM
12-15-2004 05:19 AM
Re: Inline "Sed" script
Here is something using awk,
http://www.student.northpark.edu/pemente/awk/awk1line.txt
http://www.sap-basis-abap.com/unix/awk-one-liner-tips.htm
Hope this helps.
Regds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2004 05:23 AM
12-15-2004 05:23 AM
Re: Inline "Sed" script
perl -p -i -e 's/this/that/g' allmyfiles/*
Will replace the text in all the files under directory allmyfiles.
Change option -i to -i.bu and it will save a backup of each file with an extenstion of .bu.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2004 05:23 AM
12-15-2004 05:23 AM
Re: Inline "Sed" script
#!/usr/bin/sh
TMF=/tmp/$$
PRGN=$(basename $0)
if [ $# -ne 3 ]; then
echo "$PRGN:USAGE $PRGN FILENAME CURR CHANGE"
exit
fi
if [ -s $1 ];then
cat $1| sed "s?$2?$3?g" > $TMF
if ! diff $1 $TMF 1>/dev/null ;then
cp $TMF $1
fi
else
echo "$PRGN:File $1 NOT FOUND"
fi
rm $TMF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2004 08:20 AM
12-15-2004 08:20 AM
Re: Inline "Sed" script
# sed_files.ksh SDA 12/16/03
#
# Change a string in a file and recreate the file with:
#
# string1 -> string2
#
USAGE="Usage: sed_files.ksh
#
# Example:
# sed_files.ksh OLD NEW *.ksh
#
if (( $# < 3 ))
then
print $USAGE
exit 1
fi
OLD=$1
NEW=$2
shift 2
#
for F in $*
do
if [[ -f $F ]]
then
# We have a regular file
file $F | grep -q text
if (( $? == 0 ))
then
# We have a text file
grep -q $OLD $F
if (( $? == 0 ))
then
# We have a text file with "string1" in it
cp -p $F $F.old
sed "s/$OLD/$NEW/g" $F > $F.new
mv $F.new $F
rm $F.old
fi
fi
fi
done