- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Usage of "ed" command in UNIX shell 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
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
тАО11-03-2009 02:23 AM
тАО11-03-2009 02:23 AM
Usage of "ed" command in UNIX shell script
I am using the following command in one of my scripts(UNIX shell script):-
ed ./file >>EOF
/^EVENTS
i
EVENTS=101 102 152 201
.
w
q
EOF
Now is there a way to use the ed command in the above format to replace a line with another line in a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-03-2009 03:02 AM
тАО11-03-2009 03:02 AM
Re: Usage of "ed" command in UNIX shell script
But well: the current ED sequence is searching for the string EVENTS at the beginning of a line.
Then inserts a new line.
Replace the i command by a s/old string/new string/.
I'm not ED user, but if I remember well the s command stands for "substitute".
Use "man ed" on Your system to get more precise info.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-03-2009 03:07 AM
тАО11-03-2009 03:07 AM
Re: Usage of "ed" command in UNIX shell script
http://gnv.sourceforge.net/
, or Sed
http://vms.process.com/scripts/fileserv/fileserv.com?SED
, or Awk
AWK == "$ SYS$COMMON:[SYSHLP.EXAMPLES.TCPIP.SNMP]GAWK.EXE"
to do that.
So you want to automate
edit a file, go to the line beginning with EVENTS, insert
EVENTS=101 102 152 201
save and quit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-03-2009 03:24 AM
тАО11-03-2009 03:24 AM
Re: Usage of "ed" command in UNIX shell script
Your command does work.
But I am unable to use a variable in this command, Like
var=/var/tmp --->a variable
ed ./file >>EOF
/^FILE
s/^FILE=.*/FILE=$var/
.
w
q
EOF
How can I do this????
And can you provide me the path for some good UNIX ED forums...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-03-2009 04:02 AM
тАО11-03-2009 04:02 AM
Re: Usage of "ed" command in UNIX shell script
ed probably does not evaluate or even recognize shell variables, $var is just part of the data stream, the shell does not see it. (same as on VMS). If You want to use variables, build the data in a temporary file instead of the input stream.
(and no, I can't help You with this, here is VMS land!)
And no, I don't know a specific news group for ed.
Eventually try comp.editors for (Unix) editor sopecific questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-03-2009 04:36 AM
тАО11-03-2009 04:36 AM
Re: Usage of "ed" command in UNIX shell script
And BTW, with sed the whole stuff is much easier:
sed s/oldstring/newstring/g filein > fileout
Since I'm no unix user, I leave the regexp syntax for s(ubstitution) string to You for Your case, but it certainly can contain shell variables, substituted by the shell before it reaches sed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2009 03:35 AM
тАО11-05-2009 03:35 AM
Re: Usage of "ed" command in UNIX shell script
What OS are you running? HP-UX, Linux or Tru64?
>Joseph: ed probably does not evaluate or even recognize shell variables
The shell does if they are in a here document.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2009 04:12 AM
тАО11-05-2009 04:12 AM