Removing tab spaces at the end of each line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing tab spaces at the end of each line
# 8  
Old 08-31-2015
The way you are describing your file and the results you say you are getting do not make sense to us.

Please show us the exact output you get from the commands:
Code:
uname -a

Code:
printf '%s\n' "$SHELL"

Code:
od -bc file

and
Code:
sed 's/[[:space:]]*$//' file | od -bc

# 9  
Old 09-03-2015
Thanks for replying Don.Sorry for late reply. I have executed the commands you suggested and here is the output from that.
Code:
uname -a
SunOS cvgsolsasp001 5.10 Generic_142900-06 sun4u sparc SUNW,SPARC-Enterprise

Code:
printf '%s\n' "$SHELL"
/bin/csh

Code:
od -bc headrec

0000060 061 065 060 062 062 011 061 065 060 062 062 011 061 065 060 062
           1   5   0   2   2  \t   1   5   0   2   2  \t   1   5   0   2
0000100 062 011 061 065 060 062 062 011 061 065 060 062 062 012 061 065
           2  \t   1   5   0   2   2  \t   1   5   0   2   2  \n   1   5

Code:
sed 's/[[:space:]]*$//' headrec | od -bc

0000060 061 065 060 062 062 011 061 065 060 062 062 011 061 065 060 062
           1   5   0   2   2  \t   1   5   0   2   2  \t   1   5   0   2
0000100 062 011 061 065 060 062 062 011 061 065 060 062 062 012 061 065
           2  \t   1   5   0   2   2  \t   1   5   0   2   2  \n   1   5

Kindly look into this once
Moderator's Comments:
Mod Comment Please use CODE tags for all sample input, all sample output, and all code segments.

Last edited by Don Cragun; 09-03-2015 at 03:32 AM.. Reason: Fix CODE tags.
# 10  
Old 09-03-2015
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:
Code:
/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.
# 11  
Old 09-03-2015
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
Code:
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)

Code:
      1 15022	15022	15022	15022	15022	15022
      2 15023	15023	15023	15023	15023	15023
      3 15074	15074	15074	15074	15074	
      4 15075	15075	15075	15075	15075	
      5 15080	15080	15080	15080		
      6 15113	15113	15113	15113		
      7 15172	15172				
      8 15173	15173				
      9 15174					
     10 15175					
     11 15404	15404	15404	15404	15404	15404
     12 15405	15405	15405	15405	15405	15405

Now below is the output which i want.The lines 3,4,5,6,7,8,9,10 should not contain the tab spaces at the end.

Code:
      1 15022	15022	15022	15022	15022	15022
      2 15023	15023	15023	15023	15023	15023
      3 15074	15074	15074	15074	15074
      4 15075	15075	15075	15075	15075
      5 15080	15080	15080	15080
      6 15113	15113	15113	15113
      7 15172	15172
      8 15173	15173
      9 15174
     10 15175
     11 15404	15404	15404	15404	15404	15404
     12 15405	15405	15405	15405	15405	15405

Hope this time i am clear on my need.Kindly suggest me on this.
Thanks in advance.
# 12  
Old 09-03-2015
Got Perl?
Code:
perl -ple 's/\s+$//' am24.file

This User Gave Thanks to Aia For This Post:
# 13  
Old 09-03-2015
I'm a bit surprised. Applied to you sample file in post#11, the solutions in post#1 and #2 do exactly what you want.
Code:
sed -n '9p' file | hd
00000000  20 20 20 20 20 20 39 20  31 35 31 37 34 09 09 09  |      9 15174...|
00000010  09 09 0a                                          |...|

sed -n '9 s/[ \t]\+$//p' file | hd
00000000  20 20 20 20 20 20 39 20  31 35 31 37 34 0a

All <TAB>s are removed!
This User Gave Thanks to RudiC For This Post:
# 14  
Old 09-04-2015
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".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to catch a two word keyword which may contain a new line(may include spaces or tab) in it?

How to catch a two word keyword which may contain a new line(may include spaces or tab) in it. for example there is a file a.txt. $more a.txt create view as (select from ......... .......... ( select .... ( select ...... .. select only no ((( number ( select end (12 Replies)
Discussion started by: neelmani
12 Replies

2. Shell Programming and Scripting

Adding tab/new line at the end of each line of a file

Hello Everyone, I need a help from experts of this community regarding one of the issue that I am facing with shell scripting. My requirement is to append char's at the end of each line of a file. The char that will be appended is variable and will be passed through command line. The... (20 Replies)
Discussion started by: Sourav Das
20 Replies

3. UNIX for Dummies Questions & Answers

Removing empty lines at the end of a Tab-delimited file

I'm trying to remove all of the empty lines at the end of a Tab delimited file. They have no data just tabs. I've tried may things, here are a couple: sed /^\t.\t/d File1 > File2 sed /^\t{44}/d File1 > File2 What am I missing? (9 Replies)
Discussion started by: SirHenry1
9 Replies

4. Shell Programming and Scripting

append end of line with 8 spaces

child_amt=$amount prev_line="$prev_line $child_amt" i am getting the result like this 21234567890001343 000001004OLFXXX029100020091112 0000060 but i want 8 spaces between the eg: 21234567890001343 000001004OLFXXX029100020091112 0000060 how can i do this in .ksh (1 Reply)
Discussion started by: kshuser
1 Replies

5. Shell Programming and Scripting

Removing spaces in a line

Hi All, I have a line like this " field1;field2;field3 " (single space after and before double quotes). Now i have to remove these single space . Kindly help me. Thanks in advance (2 Replies)
Discussion started by: krishna_gnv
2 Replies

6. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

7. Shell Programming and Scripting

Replace spaces between strings in a line with tab

Hi All I am having problem in substitution of any number of spaces, or a combination of space and tab in between strings in the lines of text file. Is there any way out in Perl? Please help me. e.g., Say the input is in the following format:- XX yyy zzz... (1 Reply)
Discussion started by: my_Perl
1 Replies

8. UNIX for Dummies Questions & Answers

how to append spaces(say 10 spaces) at the end of each line based on the length of th

Hi, I have a problem where I need to append few spaces(say 10 spaces) for each line in a file whose length is say(100 chars) and others leave as it is. I tried to find the length of each line and then if the length is say 100 chars then tried to write those lines into another file and use a sed... (17 Replies)
Discussion started by: prathima
17 Replies

9. Shell Programming and Scripting

to see space, tab, end of the line chracters

what can I use ?? In vi, I can use :set list <-- and see end of line $.. or use cat -A but I am wondering if there is command or program that allows me to see all the hidden characters( space, tab and etc) Please help thanks. (3 Replies)
Discussion started by: convenientstore
3 Replies

10. Shell Programming and Scripting

To Trim spaces at the end of line

Hi Friends, Can any one help with this issue: How to trim spaces for each line at the end, Like I have a file in this format. EMP1 SMITH 46373 5 STREET HOWARD 74636 EMP2 JONES 5454 { these are spaces ........} EMP3 SMITH 46373 5 STREET HOWARD 74636 EMP4 JON 2554 { these are... (1 Reply)
Discussion started by: sbasetty
1 Replies
Login or Register to Ask a Question