Well, seems to depend on the system that you use. It works for me as is on my linux system. On FreeBSD, this sed -r 's/[ ]+$//' file works, i.e. it uses the -r option to switch to EREs, and it needs an explicit <TAB> char inserted on the ( bash ) command line by Ctrl-V <TAB>.
Thanks both of you for answering my question. I am using PuTTY (which is a free implementation of Telnet and SSH for Windows and Unix platforms).
I have tried the commands which you both suggested but it did not work.I noticed one thing that when i use the commands
sed 's/[ \t]\+$//' file
and
sed 's/[[:space:]]*$//' file
the tab spaces at the end of the lines containing 6 fields are removed but not at the end of the lines containing less than 6 fields.
I mean to say when i use the above commands the tab space at the end of the line below is removed
15022 15022 15022 15022 15022 15022
and the tab space remained same at the end for these lines
---------- Post updated at 04:53 AM ---------- Previous update was at 04:50 AM ----------
One more thing i would like to add here,as Don said there are no trailing spaces in my data lines.and there is 1 tab space and 1 blank between each fields which i want to keep it as it is.and only thing is i want to remove the tab spaces at the end of each line even though the lines contains 6 fields or less than 6 fields.
Can't possibly be. Both sed solutions look just for the end-of-line and do not consider the field count. Even if there are more than one <TAB> due to missing fields, they are matched by the + sign in the regex and thus removed.
Please make sure there's no DOS line terminator (shown as \r , ^M or 0x0D )!
I asked you to show us results of running a set of commands on your sample input file. Instead of that, you showed us the results of running those commands on bytes 48 through 80 of that file showing us a single complete line of data (with no spaces at all and no trailing tabs) and two characters from the start of the next line (with no spaces and no tabs at all). So, I have no more idea now what you're trying to do than I did before.
But, now that we know you're using a Solaris system, try:
/usr/xpg4/bin/sed 's/[[:space:]]*$//' file
If this still doesn't work, you are going to have to give us the details about your file that I requested before AND a MUCH clearer explanation of what output you are trying to produce.
Thanks Don. I tried the command but it did not work. Below is the data in my file.There are thousands of lines like this in the original file.But i have taken a few here.
All these lines are having tab spaces in between the fields and some lines are having tab spaces at the end also.
The lines 1,2 and 11,12 are not having tab spaces at the end. The 3,4 lines are having 1 tab space at the end.The 5,6 lines are having 2 tabs paces at the end
and lines 7,8 are having 4 tab spaces at the end and lines 9,10 are having 5 tab spaces at the end.
I want to keep the tab spaces as it is in between fields in all these lines.But I want to remove the tab spaces at the end from the lines 3,4,5,6,7,8,9,10.
for ex:- If i give
shift$
(command for moving the cursor to the end of the line) in the line 7,then cursor should be highlighting the last digit in the line which is '2'(15172 15172)
Thank you Rudi for your reply. The both commands did not work for me when i used them on my file. I will try to see if i can get any other way.
Thanks again for your help.
---------- Post updated at 04:37 AM ---------- Previous update was at 04:11 AM ----------
Thanks Aia for your reply. When i am using 'Perl' , I am getting a warning message "Setting locale failed". I think my system does not have the supporting locale settings to use this "perl".
We have made several suggestions. We have tested them on the sample data you have provided and they do exactly what you have asked them to do.
You say they do not work. But, that doesn't help. The output you showed us in post #9 in this thread shows that the output produced is exactly what you asked for. Please pick a few lines of your input file that are NOT processed correctly and copy them into a file named bad_input . Then run the commands:
cat bad_input
od -bc < bad_input
/usr/xpg4/bin/sed 's/[[:space:]]*$//' bad_input > bad_output
od -bc < bad_output
and show us the exact, complete output (not just some 32 character sample) in CODE tags. It should be obvious by now that if we can't see what is going wrong, we can't help.