How to split this file.?

Hi Gurus,

I have a file which has only one huge line. I want to split it to multiple lines.
when I use

fold -w30 filename.

it can not split the file.
when using

fold -sw30 filename.

it works fine.
in man file, the -s break at spaces.
in previous posting, I got one script which using awk split file. it worked perfect for my old file. but it can not split this file.

awk '{for (i=1; i<=length($0); i+=10) print substr($0, i, 10)}' oldfilename > newfilename

I am wondering what I need change to make this awk script working.
when using

cat -A

I can see a special charactor ^@.
using

cat -evt

I can not see

Thanks in advance.

What do you actually mean by that?
So, do you have a null character in your input file? Try passing the input through tr .

tr -d '\0' < inputfile | fold -w30

Thanks for your quick reply.
what i tried to say is
when using

fold -sw30

,
it can split the file correctly, but when using

fold -w30

it can not split the file.

when run

 tr -d '\0' filename

I got error

tr: extra operand `filename'
Only one string may be given when deleting without squeezing repeats.

I am not sure if there is null charactor, when using

cat -A

I can see special charactor

^@

thanks

Did you read my post carefully? I said tr -d '\0' < inputfile and not what you tried.

And, ^@ is the ASCII representation of the null character (in caret notation).

1 Like

you are right. it works. one more question. how can I replace this NULL character with space?

thanks in advance.

You can do that using tr too.

tr '\0' ' ' < inputfile
1 Like

Thanks both of you.

I got another problem. the row count are different
when using

fold -sw filename

and

tr '\0'  ' ' < filename

do you know why?

thanks in advance.

fold "wraps lines" and tr does not, so that's to be expected, even if fold -sw filename is not a valid command (although I presume you mean -sw 30).

Well, rows are in databases and spreadsheets, text just has characters, lines, maybe pages. If you muck with the data, it is not always appreciated by tools that like the original. Adding data, lf characters for folding, will be different than replacing data, longer file for starters.

You have a line too long = full file and null characters. You can look at it using 'od' or similar tools, even 'cat -vt' can be useful. Maybe the nulls should be line feeds?

If you turn all the spaces into line feeds using tr, you have a lot of small lines you can concatenate as you please using the line oriented tools.