If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > remove the trailing spaces or charaters after particular format

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-21-05, 15:33
vjkiran vjkiran is offline
Registered User
 
Join Date: Feb 2005
Posts: 10
remove the trailing spaces or charaters after particular format

Hi
here is my problem.
I have a huge file , each and everly line ends with 00/00/0000 ,,,,,,,,,,,,,,,,,,( 18 commas)
All I need to do is , I have to ignore whatever the spaces or any more commas after that . Or I have to remove the remaining spaces or commas at the end of the line .
how can i do it using Unix script.

Your help will be appreciated.
Thanks
Vijay
Reply With Quote
  #2 (permalink)  
Old 02-21-05, 16:30
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
pls give a sample input AND a desired output.
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
  #3 (permalink)  
Old 02-21-05, 16:48
vjkiran vjkiran is offline
Registered User
 
Join Date: Feb 2005
Posts: 10
sampledata

abcdk l lklk dsjdl lklk sds00/00/0000,,,,,,,,,,,,,,,,,,
dsdsdsdssdsasasasasas00/00/0000,,,,,,,,,,,,,,,,,,
abcsdsdsd sdsdsdk l lklk dsjdl lklk sds00/00/0000,,,,,,,,,,,,,,,,,,
abcdk l lklk dsjdl lklk sds00/00/0000,,,,,,,,,,,,,,,,,,

this the sample data, it is ending with (00/00/0000 and 18 commas ) and some empty spaces
I need to make it ending with (00/00/0000 and 17 commas) with no spaces at the end.

Thanks in advance
vijay
Reply With Quote
  #4 (permalink)  
Old 02-21-05, 17:14
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
nawk -f vijay.awk file

vijay.awk:
Code:
BEGIN {
   PAT="sds00/00/0000,,,,,,,,,,,,,,,,,,[ ]*$"
   PATnew="sds00/00/0000,,,,,,,,,,,,,,,,,"
}
$0 ~ PAT {
      sub(PAT, PATnew, $0)
}
1
or with sed:
Code:
sed -e 's#\(00/00/0000\)[, ][, ]*$#\1,,,,,,,,,,,,,,,,,#g' file
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+

Last edited by vgersh99; 02-21-05 at 17:21.
Reply With Quote
  #5 (permalink)  
Old 02-21-05, 17:29
vjkiran vjkiran is offline
Registered User
 
Join Date: Feb 2005
Posts: 10
Thansk a lot vlad

I greatly appreciate your help and fast response.
I did in a different method also.
here is what i did. I removed all trailing spaces in first tiem then I substituted with 00/00/0000 and 18 spaces with 17 spaces.

your method also works great but it still have the trailing spaces.

Thank you very much vlad.

Vijay
Reply With Quote
  #6 (permalink)  
Old 02-21-05, 17:37
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
my version does remove trailing spaces - tested on Solaris's nawk/sed.
are you sure those are spaces? maybe tabs or control chars?
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On