HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- variables in sed
Operating System - HP-UX
1830166
Members
5441
Online
109999
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
Go to solution
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
11-01-2001 01:08 PM
11-01-2001 01:08 PM
Hi Folks,
How do I put variables in a sed command?
for e.g.
bline_no=1
eline_no=35
sed '"$bline_no", "$eline_no"d' temp.txt >temp1.txt
Actually the requirement is I need to remove some of the lines from a text file and copy it to another file. Thanks in adv.
Kris
How do I put variables in a sed command?
for e.g.
bline_no=1
eline_no=35
sed '"$bline_no", "$eline_no"d' temp.txt >temp1.txt
Actually the requirement is I need to remove some of the lines from a text file and copy it to another file. Thanks in adv.
Kris
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2001 01:25 PM
11-01-2001 01:25 PM
Solution
Hi:
This should get you started. The missing piece is 'eval'. The remainder is left as an exercise for the student.
#!/usr/bin/sh
bline_no=1
eline_no=35
eval sed -e '${bline_no},${eline_no}d' temp.txt > temp1.txt
Plan B) Build your sed commands as a script and use the -f arg.
Regards, Clay
This should get you started. The missing piece is 'eval'. The remainder is left as an exercise for the student.
#!/usr/bin/sh
bline_no=1
eline_no=35
eval sed -e '${bline_no},${eline_no}d' temp.txt > temp1.txt
Plan B) Build your sed commands as a script and use the -f arg.
Regards, Clay
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2001 01:27 PM
11-01-2001 01:27 PM
Re: variables in sed
Hi:
Try this:
sed "$bline_no","$eline_no"d temp.txt > temp1.txt
Regards!
...JRF...
Try this:
sed "$bline_no","$eline_no"d temp.txt > temp1.txt
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2001 01:32 PM
11-01-2001 01:32 PM
Re: variables in sed
Have you tried using a command file with the
-f option? The file would look like this
s/.cf//g
/default/d
/newname/d
The command string like this:
sed -f "commandfile" file.txt > file1.txt
I would recommend getting the O'Reily book on sed and awk. A lot of great stuff in there.
Enjoy
C
-f option? The file would look like this
s/.cf//g
/default/d
/newname/d
The command string like this:
sed -f "commandfile" file.txt > file1.txt
I would recommend getting the O'Reily book on sed and awk. A lot of great stuff in there.
Enjoy
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
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