# How to split vCards lines

Related to How to join vCards lines, vCard does an unusual sort of line splitting: If a line has greater than 75 personalities, insert a "CR, LF, space" series. Hence the adhering to line:

123456789A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789K123456789L123456789M123456789N123456789O123456789P123456789Q123456789R123456789S123456789U123456789V123456789W123


needs to be divided right into the adhering to lines:

123456789A123456789B123456789C123456789D123456789E123456789F123456789G12345
6789H123456789I123456789J123456789K123456789L123456789M123456789N123456789
O123456789P123456789Q123456789R123456789S123456789U123456789V123456789W123


You can not simply insert the line split series every 75 personalities, due to the fact that after that there would certainly be greater than 75 personalities per line once more, and also you can not simply insert after counting 75 personalities due to the fact that it need to just be put if the line is longer than 75 personalities. One means to do it is to duplicate the adhering to command till the input no more adjustments:

sed -e 's/^$.\{75\}$$[^\r]$/\1\r\n \2/' < file | sed -e '...' | ...


That is clearly not mosting likely to collaborate with indeterminately lengthy lines, and also is badly ineffective. Just how would certainly you do this type of substitute?

1
2022-06-07 14:31:44
Source Share

To your manuscript you just require to add 2 commands: P (print approximately the first newline) and also D (delete approximately the first newline and also repeat if there is any kind of message left).

sed -e '{ s/$.\{75\}$$.$/\1\n \2/; P; D }' file

4
2022-06-07 14:59:44
Source

This is a not - so - wonderful effort to address the trouble:

#!/usr/bin/awk -f

{
if (length($0) > 76) { printf("%s\r\n ", substr($0, 1, 75));
$0 = substr($0, 76);
while (length($0) > 74) { printf("%s\r\n ", substr($0, 1, 74));
$0 = substr($0, 75);
}
}
print \$0;
}

2
2022-06-07 14:52:19
Source