- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: sed-append question
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-25-2006 08:25 AM
09-25-2006 08:25 AM
load /BC/TOC1
load /BC/TOC2
I want to add one more load after the last one, in this case: "load BC/TOC2"
sed "/^load/a\load /BC/TOC3" $file
it runs the sed twice :-( like the following
load /BC/TOC1
load /BC/TOC3
load /BC/TOC2
load /BC/TOC3
how do I change the sed statement to only append to the last one?
the desired output will be
load /BC/TOC1
load /BC/TOC2
load /BC/TOC3
thank you
Solved! Go to Solution.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2006 08:39 AM
09-25-2006 08:39 AM
Re: sed-append question
echo " load/BC/TOC3" >> filename
Abhijeet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2006 08:42 AM
09-25-2006 08:42 AM
Re: sed-append question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2006 09:16 AM
09-25-2006 09:16 AM
Re: sed-append question
Try:
# cat ./append
#!/usr/bin/sed -f
n
/^load TOC2/p
a\
load \/BC\/TOC3
...run as:
# ./append file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2006 10:03 AM
09-25-2006 10:03 AM
Re: sed-append question
Sorry, that should look like:
# cat ./append
#!/usr/bin/sed -f
#!/usr/bin/sed -f
/^load \/BC\/TOC2/{
a\
load \/BC\/TOC3
}
...run as:
# ./append file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2006 10:53 AM
09-25-2006 10:53 AM
Re: sed-append question
the last entry may not always be /BC/TOC2, it can be /BC/TOC3, /BC/TOC4, the whole point is how to append the new entry just ONCE?
thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2006 11:21 AM
09-25-2006 11:21 AM
Re: sed-append question
# cat ./append
#!/usr/bin/sed -f
${
a\
load \/BC\/TOC_
}
# ./append file
...will append to the file's end.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2006 12:17 PM
09-25-2006 12:17 PM
Re: sed-append question
is the difference between yours and mine the "_"? I still get the same result :-(
please help out...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2006 12:29 PM
09-25-2006 12:29 PM
Re: sed-append question
Well, mine works for me, so try this variation:
# #!/usr/bin/sed -nf
p
${
a\
load \/BC\/TOC_
}
...substitute anything you want for "TOC_".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2006 12:39 PM
09-25-2006 12:39 PM
Solution#!/usr/bin/ksh
FILE=itrc_append
# fine last "load"
line=$(grep -n "^load" $FILE | tail -1 | sed 's/:.*$//')
# add one "load /BC/TOC3" after the last "load".
sed -e "${line}a\\
load /BC/TOC3" $FILE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2006 01:10 PM
09-25-2006 01:10 PM
Re: sed-append question
I should give a complete file to make my point clear
the file is like
----------------------
load /BC/TOC1
load /BC/TOC2
description: testing
vob: bc
---------------------
so, I can not just append at the end of the file..I need to append at the end of the load statement..
the solutions above are all at the end of the file.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2006 01:36 PM
09-25-2006 01:36 PM
Re: sed-append question
Mine is not. I find the LAST "load" and add after it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2006 01:57 PM
09-25-2006 01:57 PM
Re: sed-append question
sed '
/^load/,/^$/{
/^$/{i\
load /BC/TOC3
}
}' infile
~hope it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2006 02:25 PM
09-25-2006 02:25 PM
Re: sed-append question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2006 12:26 PM
09-26-2006 12:26 PM
Re: sed-append question
I also like Sandman's solution, but I have question about your synatx
sed '
/^load/,/^$/{
/^$/{i\
load /BC/TOC3
}
}' infile
1.what does the first/second line mean?
I am confused at
/^load/,/^$/{
/^$/{i\
that is a new synatax to me..
please kindly shed some light..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2006 01:13 PM
09-26-2006 01:13 PM
Re: sed-append question
Basically for all lines from the first "load" to a blank line, do the {} block. Inside the block it tests to make sure it is on the blank line and if so, insert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2006 06:20 PM
09-26-2006 06:20 PM
Re: sed-append question
----------------------
load /BC/TOC1
load /BC/TOC2
description: testing
vob: bc
----------------------
>I am confused at
>/^load/,/^$/{
>/^$/{i\
...it's a nested sed construct which applies commands at a particular address which is within the selected block. So the above command grabs all lines that start with the word load (^load) upto the first blank line (^$). Once it reaches the blank line it inserts the desired line above the blank one.
hope it helps!