HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- edit a file in non interaction mode in shell scrip...
Operating System - HP-UX
1837240
Members
5494
Online
110115
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
06-21-2002 03:05 PM
06-21-2002 03:05 PM
edit a file in non interaction mode in shell scripts
hi,
I need to delete some lines with certain pattern ( eg. $ABC, and $ABC value varies each time in the loop) in a file and then save the changed file.
how can it do this with vi or ed? I do not want to use sed because sed can not change the original, redirection is not preferable in my case.
Please give me a example.
Thanks for the help.
I need to delete some lines with certain pattern ( eg. $ABC, and $ABC value varies each time in the loop) in a file and then save the changed file.
how can it do this with vi or ed? I do not want to use sed because sed can not change the original, redirection is not preferable in my case.
Please give me a example.
Thanks for the help.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2002 04:50 PM
06-21-2002 04:50 PM
Re: edit a file in non interaction mode in shell scripts
Well if you insist on doing this without making temp files, here you go:
perl -i.safe -n -e 'if (!(m/ABC/)) { print $_;}' file1 file2 myfile*
That will delete all lines with 'ABC' in them
in files file1, file2, and myfile* AND it will create backup copies file1.safe file2.safe ...
If you just use the -i without a suffix, no backup will be created.
If your search pattern changes; you could write a shell script to build your perl script 'on the fly' and then invoke.
I warn you that running this with the -i.safe is dangerous because you are doing it in place so test throughly before using this.
man perlrun to get an idea of what this is doing. The -n argument loops over ever line of input.
perl -i.safe -n -e 'if (!(m/ABC/)) { print $_;}' file1 file2 myfile*
That will delete all lines with 'ABC' in them
in files file1, file2, and myfile* AND it will create backup copies file1.safe file2.safe ...
If you just use the -i without a suffix, no backup will be created.
If your search pattern changes; you could write a shell script to build your perl script 'on the fly' and then invoke.
I warn you that running this with the -i.safe is dangerous because you are doing it in place so test throughly before using this.
man perlrun to get an idea of what this is doing. The -n argument loops over ever line of input.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2002 05:32 PM
06-21-2002 05:32 PM
Re: edit a file in non interaction mode in shell scripts
Hi all,
I figured out the answer,
#!/usr/bin/ksh
EPI_ID=ABC
ed abc.txt < 1,$ g/$EPI_ID/d
.
w
q
EOF
Thanks,
Jane
I figured out the answer,
#!/usr/bin/ksh
EPI_ID=ABC
ed abc.txt <
.
w
q
EOF
Thanks,
Jane
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP