- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: sed how to
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
11-20-2000 07:37 AM
11-20-2000 07:37 AM
- remove all blank lines
- change the last occurance of a comma (,) to a left paren
any ideas
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 07:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 07:50 AM
11-20-2000 07:50 AM
Re: sed how to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 08:07 AM
11-20-2000 08:07 AM
Re: sed how to
Is the comma the last character of the line? If so, then the first two suggestions will work fine. If you mean the last comma, but not necessarily the last character, try the following:
sed -e '/^$/d' -e 's/,[^,]*$/(/'
Hope this helps,
Bruce
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 08:24 AM
11-20-2000 08:24 AM
Re: sed how to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 08:26 AM
11-20-2000 08:26 AM
Re: sed how to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 08:36 AM
11-20-2000 08:36 AM
Re: sed how to
To change the last occurrence of ',' try the following:-
sed -e '/^$/d' -e 's/\(.*\),\(.*\)/\1(\2/'
Hope the backslashes appear! there's enough of them.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 08:46 AM
11-20-2000 08:46 AM
Re: sed how to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 08:50 AM
11-20-2000 08:50 AM
Re: sed how to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 08:58 AM
11-20-2000 08:58 AM
Re: sed how to
Check this very well and run into another file as indicated: cat filename |sed -e '/^$/d' -e 's/\(.*\),\(.*\)/\1)\2/' > newfilename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 09:45 AM
11-20-2000 09:45 AM
Re: sed how to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 09:50 AM
11-20-2000 09:50 AM
Re: sed how to
This one works for sure:
sed -e '/^$/d' -e 's/\(,\)\([^,]*$\)/)\2/' < infile
Explanation:
/^$/d deletes empty lines
s/\(,\)\([^,]*$\)/)\2/ substitutes a comma (1st matching item) followed by 0 or more non-commas up to the end of line (2nd matching item) by a right paren followed by the 2nd match item
Matching Items are delimited by \( and \) in the search string
Best regards,
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 11:08 AM
11-20-2000 11:08 AM
Re: sed how to
This is first line,
This is second line,
This is the last line,
I want to leave commas on first and second line alone and change the comma on the last line to a right paren ).
Solution should be:
This is first line,
This is second line,
This is the last line)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 11:19 AM
11-20-2000 11:19 AM
Re: sed how to
line1,
line2,
line3)
or is there a variety? Many files, or just one short one?
awk can use the same sed commands, but you have the ability to count, track record numbers, etc....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 11:38 AM
11-20-2000 11:38 AM
Re: sed how to
try this
awk 'BEGIN{
line="";}
{
if(length($0)==0)continue;
if(length(line)>0)print line;
line=$0;
}
END{
sub(",$",")",line);
print line;
}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 11:47 AM
11-20-2000 11:47 AM
Re: sed how to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 02:02 PM
11-20-2000 02:02 PM
Re: sed how to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 02:05 PM
11-20-2000 02:05 PM
Re: sed how to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2000 10:35 PM
11-20-2000 10:35 PM
Re: sed how to
We don't have 'tac' but we have 'rev' which prints every line backwards
one solution could be:
rev infile | sed -e '/^$/d -e '$s/,/)/' | rev > outputfile
or
sed -e '/^$/d' < infile | sed -e '$s/\(,\)\([^,]*$\)/)\2/'
will both replace the last comma of the last non blank line by a right paren, even if it's not the last character on the line,providing there is a comma on that line.
Dan