- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sed -- last field replace
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
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
тАО01-16-2007 12:53 PM
тАО01-16-2007 12:53 PM
text file ...
hello"|"\388"|"376"|""
hello"|"\388"|"376"|"meANDyou"
sed file
s/|""$/Z/g
results ..
hello"|"meANDyou"|"\388"|"376"Z
hello"|"meANDyou"|"\388"|"376"|"meANDyou"
using sed how can I replace the "meANDyou" or any other quoted text or digits that is on the end of the line with a Z ?
Steve
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2007 06:20 PM
тАО01-16-2007 06:20 PM
Solutionsed -e 's/|".*"$/Z/'
Did you want to replace quoted numbers or just raw numbers? For the latter:
sed -e 's/|[0-9]*$/Z/'
And you can combine both -e patterns.
Hmm, this doesn't work because it will replace your "\388" string too. So you may need to use awk -f"|" and replace field $4.
Or using this sed pattern assuming 4 fields with "|":
's/\(.*\)|\(.*\)|\(.*\)|".*"$/\1|\2|\3|Z/'
This takes the fields apart and only puts back the first 3.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2007 07:07 PM
тАО01-16-2007 07:07 PM
Re: sed -- last field replace
#!/usr/bin/sh
cat a.lis
awk -F'|' '{
for (i=1;i
printf "Z"
printf "\n";
}' < a.lis
Produces:
hello"|"\388"|"376"|""
hello"|"\388"|"376"|"meANDyou"
hello"|"\388"|"376"|Z
hello"|"\388"|"376"|Z
First two lines are the original input, next two the output.
Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
You currently have only awarded points to 1 of 23 answers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2007 08:57 PM
тАО01-16-2007 08:57 PM
Re: sed -- last field replace
it is not clear, if you want to have the additional string enclosed in double quotes or have the double quotes of the last field replaced.
txt='hello"|"\388"|"376"|"meANDyou"'
First (Leave quotes):
echo $txt |sed 's/[^"]*"$/Z"/'
hello"|"\388"|"376"|"Z"
Second (drop quotes):
echo $txt |sed 's/"[^"]*"$/Z/'
hello"|"\388"|"376"|Z
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2007 06:58 AM
тАО01-17-2007 06:58 AM
Re: sed -- last field replace
That works perfectly
Thank you,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2007 06:59 AM
тАО01-17-2007 06:59 AM
Re: sed -- last field replace
Hd the answer I was needing and the other had solutions too :)