cutting long text by special char around 100 byte and newline

Regard,

How can i cut the text by special char(|) around 100 byte
and write the other of the text at newline using Perl.

2|01|2059140001|34232883774|504106542|2733|2127292||55197897292|||||177011612201|87829918247|20111127|0|0|0|295438|251|573|0|0|0|0|0|0|0|0|0|0|0|54630|45890|93609|0|0|0|295330|0|0|||0

Thanks.

Try this...

awk -F'|' '{for(i=1;i<=NF;i++){s+=length($i)+1;if(s<=100){printf $i OFS}else{print $i OFS;s=0}}printf"\n"}' 
OFS='|' input_file

--ahamed

1 Like
$ split -b 100 infile ; cat xa*

Then remove the temporarily created files ..

1 Like
# ./justdoit_sp infile
2|01|2059140001|34232883774|504106542|2733|2127292||55197897292|||||177011612201|87829918247|2011112
 7|0|0|0|295438|251|573|0|0|0|0|0|0|0|0|0|0|0|54630|45890|93609|0|0|0|295330|0|0|||0
 ## code ##
l=100;for((i=1;i<=$(wc -c <$1);i=i+100)) ; do
l=$(($i+$l));cut -c${i}-$l $1 ;done
1 Like