how to have ENTER after each symbol.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to have ENTER after each symbol.
# 1  
Old 01-30-2009
how to have ENTER after each symbol.

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
# 2  
Old 01-30-2009
assume the data is in a file called inputfilename, you can use awk:
Code:
#!/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

# 3  
Old 01-30-2009
the above code in giving some error

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
# 4  
Old 01-30-2009
Are you coding in bash?
# 5  
Old 01-30-2009
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
# 6  
Old 01-30-2009
try extra ticks:

Code:
sed -r 's/.{'$x'}/&\n/g' inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Loop logic, enter into respective IF as per enter input file name

have three big data file, however I just need to see the mentioned below one line form the all the file which has SERVER_CONNECTION Value File 1 export SERVER_CONNECTION=//dvlna002:10001/SmartServer File2 export SERVER_CONNECTION=///SmartServer File3 export... (1 Reply)
Discussion started by: Nsharma3006
1 Replies

2. Emergency UNIX and Linux Support

Unable to enter the DB

Hi folks, I am on a very critical situation. I have a sun Solaris 10 MC with oracle 10G installed on it. When i try to mount the DB, I can mount it, But when I try to access it, the DB is inaccessible. SQL> select status from v$instance; STATUS ------------ MOUNTED SQL> shutdown... (6 Replies)
Discussion started by: vivek.goel.piet
6 Replies

3. UNIX for Dummies Questions & Answers

Tab and Enter

Do Tab or Enter behave like a command in some cases? For example, I had been trying to plot with gnuplot by usinf shell script like command inside: cat plot.gnu gives : plot 'datafile1' , \ 'datafile2' Now gnuplot doesn't recognize the newline command "\" unless I use "enter" in the... (12 Replies)
Discussion started by: hbar
12 Replies

4. Shell Programming and Scripting

remove enter

Hi All, I have a file , delimited by | Last column of the file has a extra enter causing error in my program Eg: firstworld <enter>; NO EMP i want data to be firstworld; NO EMP Is there a way to remove enter from a file (2 Replies)
Discussion started by: gwrm
2 Replies

5. Solaris

/usr/lib/passwdutil.so.1: symbol __nsl_fgetspent_r: referenced symbol not found

deleteing post (0 Replies)
Discussion started by: dshakey
0 Replies

6. Shell Programming and Scripting

Trigger Enter

Hello, I need to trigger every time enter has been clicked while some one on terminal i tried to googleit but with out result any idea ?? thanks in advance (3 Replies)
Discussion started by: AYAK
3 Replies

7. Solaris

Enter to OBP

Hello, today i'm comment in /etc/vfstab fs /usr and my server load in SingleUser without anything commands :( How i can enter to OBP from # ? or ILOM ? I'm try CTRL+BREAK (F5) , CTRL+ALT+BREAK (F5) and #. but it's don't help me :(((( (5 Replies)
Discussion started by: jess_t03
5 Replies

8. Solaris

Cant enter password

When i come to the login screen i will put root and no password, and it will say its incorrect, but even when i try to enter a password nothing comes up in the box (2 Replies)
Discussion started by: possuman72
2 Replies

9. Shell Programming and Scripting

HELP with Enter Character

I'm using PHP in my site. I have txt files for news. I reads the txt files and post the news. i have a php function that finds the caracter asc(13) which is the enter, and puts a <br>. It works in Windows, but not on Unix. Can u help me with that. Thanks (1 Reply)
Discussion started by: zecarlos
1 Replies
Login or Register to Ask a Question