- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- How to split strings from seperators
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
тАО08-03-2005 01:16 AM
тАО08-03-2005 01:16 AM
Is there any way to convert "07/22/2005,19:22:54" to
07222005192254 i.e. get rid of all the seperator in between such as "/", "," and ":"..
I tried using sscanf but it doesnt seems to work.
and sadly I can only use C programming...
Best regards
Henry
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2005 01:21 AM
тАО08-03-2005 01:21 AM
Re: How to split strings from seperators
a simple way is to delete them, e.g.:
# echo "07/22/2005,19:22:54"| tr -d "\/|,|:"
regards,
John K.
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2005 01:23 AM
тАО08-03-2005 01:23 AM
SolutionThere's several trivial ways you could do this using simple C code, e.g. just reading the string a byte at a time and not copying those characters that appear in a second string.
You could also do something similar using 'strtok()', with the second string being the set of delimiters, and just build up the target string from the returned substrings.
Andrew
- Tags:
- strtok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2005 01:27 AM
тАО08-03-2005 01:27 AM
Re: How to split strings from seperators
date +%m%d%Y%H%M%S
will get that same output...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2005 11:10 AM
тАО08-03-2005 11:10 AM
Re: How to split strings from seperators
Henry,
Here is a "C" solution that I threw together in a few minutes. No warranty implied or expressed. :-)
(Attached is a Notepad text file version preserving indentations). Good luck.
#include
#include
#include
#include
#define MAXTOK 255
#define MAXBUF 1024
int main()
{
int i = 0;
char *string = "07/22/2005,19:22:54";
char *delims = "/,:";
char *tokens[MAXTOK];
char *buffer;
char **x;
/* Allocate a static buffer */
/* NOTE: there are all kinds of do's and don'ts about using malloc. */
/* Please research the correct/safe method for your site. */
if( (buffer = malloc(MAXBUF)) == NULL )
{
fprintf( stderr, "ERROR: malloc() failed.\n" );
exit( 1 );
}
/* Initialize the buffer to all NULLs */
memset( buffer, '\0', MAXBUF );
/* Use strtok to break strings up by delimiters */
tokens[0] = strtok(string, delims);
while (tokens[++i] = strtok(NULL, delims));
/* Pointer arithmetic ahead; not for the faint of heart */
x = tokens;
while( *x != NULL )
{
/* printf( "%s\n", *x ); */
strcat( buffer, *x );
x++;
}
printf( "%s\n", buffer );
}
-- Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2005 12:46 PM
тАО08-03-2005 12:46 PM