I want to know script for
Input file : 123456789
outputfile :
1
2
3
4
5
6
7
8
9
now please how can generalize it
like i want output : 123
456
789
I want to know script for
Input file : 123456789
outputfile :
1
2
3
4
5
6
7
8
9
now please how can generalize it
like i want output : 123
456
789
assume the data is in a file called inputfilename, you can use awk:
#!/bin/ksh
# one parameter: spacing
spacing="$1"
awk -v spc=$spacing '{ for(i=1; i<=length($0); i++) {
printf( (i%spc == 0)?"%s\n":"%s", substr($0,i,1))
}} END { printf "\n"}' inputfilename
can it be done using sed and cut somehow .
-----------------------------------------
like to cut the 1st variable cut -c1-1
and then to replace the 1st variable sed '1s/^.//
-------------------------------------------------------
but my problem is I can't generalize it mean
if I set x=1
than
12345
will become
1
2
3
4
5
if i set x=2
12
34
5
and so on
I am poor at understanding awk
where is the to write the output file ??
ya there is input and output file
Are you coding in bash?
no in ksh
but getting >
at the end of the code
now i can do
sed -r 's/.{2}/&\n/g' inputfile
or sed -r 's/.{3}/&\n/g' inputfile
it works but i want to generalize it replacing 2 or 3 with x. which doesn't work
try extra ticks:
sed -r 's/.{'$x'}/&\n/g' inputfile