Using DD


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using DD
# 1  
Old 05-03-2005
Lightbulb Using DD

Hi,
I've got a file of one line and I want to cut it in n lines of 160 caracters each.

For this I use the following command
dd if=myfile of=result cbs=160 conv=unblock

It work's fine but the spaces at the end of the line are truncated.
Do you have any idea ?
Thanks
# 2  
Old 05-03-2005
unblock and block truncate trailing blanks - that is expected behavior.
Assuming the line is really long and you can't use awk try:
Code:
/*********************************
* block.c 
* to compile:
*  gcc -o block block.c
*  or 
*  cc -o block block.c
*  
* usage:  block [filename] > outputfile  
*
**********************************/
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[1])
{
    int ch=0;
    int counter=0;
    FILE *in=NULL;
    if(*argv[1])
    {
        in=fopen(argv[1],"r");	
            if(in==NULL)
        {
            perror("");
            exit(EXIT_FAILURE);
        }
    }
    else
    {
        in=stdin;	
    }
    while( (ch=fgetc(in))!=EOF)
    {
        fprintf(stdout,"%c", ch);
        counter++;
        if(counter%160 == 0)
        {
            fprintf(stdout,"\n");
        }
    }
    if(counter%160)
    {
        while(counter%160)
        {
            fprintf(stdout,"%c",' ');
            counter++;
        }
        fprintf(stdout,"\n");
    }
    return 0;
}

# 3  
Old 05-03-2005
man fold

echo '123456789' | fold -w 3
# 4  
Old 05-03-2005
fold is limited to 2048 characters lines - on POSIX
# 5  
Old 05-04-2005
Thanks it works fine
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question