- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk or sed
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
09-11-2002 10:28 AM
09-11-2002 10:28 AM
awk or sed
I have number of pro*c and .sql file which contain,
substr(a.st_no,1,3) OR substr(st_no,1,3).
I want to change it to,
substr(a.st_no,1,4) OR substr(st_no,1,4).
How can i do this using awk or sed?
Thanks in adv.
(Pts. will be given to each response.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2002 10:35 AM
09-11-2002 10:35 AM
Re: awk or sed
I think sed is best for this.
sed 's/substr(a.st_no,1,3)/substr(a.st_no,1,4)/' file1 >file2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2002 10:37 AM
09-11-2002 10:37 AM
Re: awk or sed
# sed 's/st_no,1,3/st_no,1,4/g' filename > filename.new
Do a quick for loop for say all files that has ".sql" extension.
# for i in `ls *.sql`
>do
>sed 's/st_no,1,3/st_no,1,4/g' $i > $i.new
>done
#
The *.sql.new files are the ones with the replaced string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2002 11:37 AM
09-11-2002 11:37 AM
Re: awk or sed
find PATHWHEREFILESLIVE -type f -name "*.sql" -exec grep -l -e "substr(a.st_no,1,3)" -e "subs
tr(st_no,1,3)" {} \; |
awk '{printf("sed -e \"s/substr\(a.st_no,1,3\)/substr\(a.st_no,1,4\)/\" -e \"s/s
ubstr\(st_no,1,3\)/substr\(st_no,1,4\)/\" %s > %s.dummy; mv %s.dummy %s\n", $1, $1,
$1, $1); }' |xargs -i sh {}
BUT PLEASE make SURE YOU BACKUP your files FIRST!!!!!!!!!
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2002 11:53 AM
09-11-2002 11:53 AM
Re: awk or sed
perl -i -ne 's/st_no,1,3\)/st_no,1,4\)/g;print' yourfile
Note that this (-i option) will edit IN PLACE, overwriting your original files with the changes. To preserve your old files, save a copy, or use:
perl -i.bak -ne 's/st_no,1,3\)/st_no,1,4\)/g;print' yourfile
to keep copies with *.bak name.
Tom