- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: remove comma (,) from end of the line ?
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
05-24-2006 01:27 AM
05-24-2006 01:27 AM
123,456,2323,23232,
1) Using either shell or perl command,How do I remove the last comma after 23232 ?
2)When I try to view it (vi data.txt), I get
"data.txt" Line too long
message. How do I edit the file ?
The file actually has about 1200 numbers separated with comma.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2006 01:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2006 01:33 AM
05-24-2006 01:33 AM
Re: remove comma (,) from end of the line ?
please no points for this second part.
vi has a limit of 2048 (or now 4096) characters on one line. Solutions seems to be to either split the file or use alternate editor.
See
http://forums1.itrc.hp.com/service/forums/bizsupport/questionanswer.do?threadId=33157
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2006 01:46 AM
05-24-2006 01:46 AM
Re: remove comma (,) from end of the line ?
Thanks.
Your command works beautifully on a small file.
# sed "1,$ s/,$//" try
123,456,2323,23232
But this file, which has one line of 9490 characters yields nothing.
# wc -m data.txt
9490 data.txt
# sed "1,$ s/,$//" data.txt
This yields nothing.
I have to run more command to look at the file. Could be file length problem again (I guess).
Attaching data.txt file as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2006 02:00 AM
05-24-2006 02:00 AM
Re: remove comma (,) from end of the line ?
what about
perl -pne 's/,$//;' data.txt
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2006 02:05 AM
05-24-2006 02:05 AM
Re: remove comma (,) from end of the line ?
Use Perl;
# perl -pe 's/,$//' file
...or to update "inplace":
# perl -pi.old -e 's/,$//' file
That last variation creates a backup of "file" as "file.old" and recreates "file" to your specification.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2006 02:09 AM
05-24-2006 02:09 AM
Re: remove comma (,) from end of the line ?
Peter G,
Thanks for the link as i am going to split the file and then sed will probably work.
Peter N,
You are right on because the Pete G. sed command would not parse this (9490 characters) long file but your perl command did as the data1.txt file
does not have comma. I am viewing this file by doing more and not vi.
perl -pne 's/,$//;' data.txt > data1.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2006 02:12 AM
05-24-2006 02:12 AM
Re: remove comma (,) from end of the line ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2006 08:34 AM
05-24-2006 08:34 AM
Re: remove comma (,) from end of the line ?
# perl -pne 's/,$//;' data.txt
is wrong, as the options -n and -p are contradicting
# perl -pe's/,$//' data.txt
is the correct syntax, and indeed for the in-file change
# perl -pi -e's/,$//' data.txt
making it even more defensive:
# perl -pi -e's/,\s*$//' data.txt
allows optional trailing whitespace (which will also be removed)
Enjoy, Have FUN! H.Merijn