- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: add new string using 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
01-28-2004 02:59 AM
01-28-2004 02:59 AM
add new string using sed
I have a shell variable $x.
# echo $x
HELLO UNIX
I also have an ASCII file hello.txt.
#cat hello.txt
HELLO LINUX
HELLO WINDOWS
How can I add a value of the shell variable $x to the end of my file using sed?
"cat $x >> hello.txt" is not useful to me.
Your help with SED statement is appreciated.
Thanks,
Sergejs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 03:03 AM
01-28-2004 03:03 AM
Re: add new string using sed
This will worl just fine and will do the job with the file in place:
echo "${x}" >> hello.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 04:31 AM
01-28-2004 04:31 AM
Re: add new string using sed
Perhaps you could tell us more about the application that you want to use this in or explain why you want to use sed to do this operation ?
Best regards,
Kent M. Ostby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 04:39 AM
01-28-2004 04:39 AM
Re: add new string using sed
You will need to use 'echo' instead of "cat" to print $x into hello.txt.
echo "$x" >> hello.txt
If you insist of sed, below is the way
sed 's/$/'"$x"'/' hello.txt > 1
mv 1 hello.txt
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 09:30 PM
01-28-2004 09:30 PM
Re: add new string using sed
It's better to do that with ex :
#ex -s FILE << EOF
> /^TOTO/
> s/TOTO/TOTO2/
> w
> EOF
TOTO=variable
TOTO2=new variable
Best regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 09:52 PM
01-28-2004 09:52 PM
Re: add new string using sed
#echo >> hello.txt
#sed /^$/s/^$/"$x"/g hello.txt
HELLO LINUX
HELLO WINDOWS
HELLO UNIX
However here I assume that there are no blank lines else where in this file than the end of file.
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2004 10:27 PM
01-28-2004 10:27 PM
Re: add new string using sed
create a file (sedfile in this example) with the following two lines,
$a\
Whatever string you want
sed -f sedfile hello.txt
cat hello.txt
HELLO LINUX
HELLO WINDOWS
Whatever string you want
However sed can not substitute the variables with in the input file.
-Karthik S S