- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: sed help
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
тАО02-04-2008 08:30 AM
тАО02-04-2008 08:30 AM
sed help
I use vi to edit the file, and search and replace all the trailing space like so
:%s/[ ]*$//
Although, when I try to use sed, I am not able to edit the file at all. Here is how I am trying to do this
cat filename | sed -e 's/[ ]*$//'
This does not edit the file at all. What could I be doing wrong? Any help is greatly appreciated.
-S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2008 08:48 AM
тАО02-04-2008 08:48 AM
Re: sed help
cat fielname | tr -d '\032* $'
Although, I need to confirm it with the QA ppl to make sure the file works for them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2008 10:24 AM
тАО02-04-2008 10:24 AM
Re: sed help
sed -e 's/[ ]*$//g' filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2008 10:46 AM
тАО02-04-2008 10:46 AM
Re: sed help
It should work asis, that is without 'g' flag. Under HP-UX it works well.
As far as I know, regular expressions are satisfied with the largest number of characters that can match the expression. If it was not the case, and IMHO, '*' in a regular expression would have no sens. And '[ ]*$' clearly means : 0 or more spaces before end of line ! So it shoul work.
Don't know Linux as well as HP-UX but maybe there is a limitation on implementation of sed. Maybe there is a special option to tell 'sed' to use extended regular expressions ? I have this beahavior under HP-UX with 'grep' : if you don't use -E option, 'grep' doesn't treat correctly all regular expressions.
An other idea : '[]' is used to match a list of characters. As you have only one character, space, may be '[ ]' is not correctly interpreted ? So try this :
cat filename | sed -e 's/ *$//'
Hope this will help
Regards
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2008 12:16 PM
тАО02-04-2008 12:16 PM
Re: sed help
If you want to edit a file in place, you can use:
perl -pi -e 's/\s+$//' filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2008 10:43 PM
тАО02-04-2008 10:43 PM
Re: sed help
slydmin, in order to actually update the content of the file you can redirect the output:
sed -e 's/[ ]*$//g' > newfile; mv newfile origfile;
make sure you have a backup of the original file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2008 08:31 AM
тАО02-05-2008 08:31 AM
Re: sed help
I was actually doing that, but did not mention in my original email.
sed -e 's/[ ]*$//'
I tried everyone's suggestion but none gave desired output.
I have a csv file, with say about 14 comma separated fields. The last field has a lot of spaces in it.
vim works like a charm (:%s![ ]*$!), although we are going to have a large number of files to process and manually doing it does not make sense.
So this attempt to use same regex with sed does not work. tr -d \032 works, although it removes white space from everywhere in the file.
I will copy 3 lines from the file and attache it herewith, although the data is changed.
I am stumped at this point.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2008 08:59 AM
тАО02-05-2008 08:59 AM
Re: sed help
Just found this at http://pwet.fr/man/linux/commandes/sed :
-r, --regexp-extended
use extended regular expressions in the script
It sounds like like -E option for grep with HP-UX, no ?
Could you try to add -r option and tell us ?
Regards
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2008 09:16 AM
тАО02-05-2008 09:16 AM
Re: sed help
I thought I had tried that (sed -r). But I gave it a try and it did not work.
What is interesting though, the file I uploaded , if that were to be manipulated with sed -r 's/[ ]*$//g' , I get the desired output but not on the original file.
The original file has a line count of about 25000. I tried splitting it up in to 5000 line files, but still am not having success.
I am going to try and use perl to see if I can use the expression posted to my OP (it removed all spaces, just like tr -d\032).
Thanks,
-S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2008 09:37 AM
тАО02-05-2008 09:37 AM
Re: sed help
It removes the white space(s) at the end of the line, but not all new lines are lost.
2nd line is not a continuation of the 1st.
Will try a few more things, but I stand corrected on the tr /perl comparison.