| |
|
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.
|
 |

02-21-05, 15:33
|
|
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
|
|

02-21-05, 16:30
|
|
Registered User
|
|
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
|
|
pls give a sample input AND a desired output.
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
|
|

02-21-05, 16:48
|
|
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
|
|

02-21-05, 17:14
|
|
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.
|

02-21-05, 17:29
|
|
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
|
|

02-21-05, 17:37
|
|
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> |
+-----------------------+
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|