how to separate every 10 characters then space then another 10 charactes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to separate every 10 characters then space then another 10 charactes
# 1  
Old 10-22-2007
how to separate every 10 characters then space then another 10 charactes

suppose u have a file
P2122 AAJJSKKSKSLSKSKMSKMS
P2123 AASSJMWJNSJNWHNSKSJ
P2126 AHJMKNSAJNSKAKMOKALM
P3533 KKKSJMAKKLLMLMSLMSPM

P2122 JKKSKKMKKSKKKS--------------NSNJ
P2123 NSJN---------MSKMKMKKSLLNSLL
P2126 JNJSJNWKMSK-------------SKKSMK
P3533 JSNSNPWLLL-SKK----SKKKSKKS

so the output shud be
P2122 AAJJSKKSKS LSKSKMSKMS
P2123 AASSJMWJN JNWHNSKSJM
P2126 AHJMKNSAJN SKAKMOKALM
P3533 KKKSJMAKKL LMLMSLMSPM

P2122 JKKSKKMKKS SLSKSKMSKM
P2123 NSJN---------MS KMKMKKSLLN SLL
P2126 JNJSJNWKMS K-------------SKK SMK
P3533 JSNSNPWLL- SKK------SKKK SKKS
# 2  
Old 10-22-2007
In principle this is easy (replace "<b>" by a literal blank):

's/[^<b>]\{10\}/&<b>/g'

But i take it from your example that the substitution should only take place in the middle of a line leaving the other fields intact:

input:
NotToBeChanged 01234567890123456789 NotToBeChanged

output:
NotToBeChanged 0123456789 0123456789 NotToBeChanged

It depends on the structure of your input file how to refine the regexp then. In your example my solution would work because the first field is less than 10 characters long. If you have trouble with it pls come back here.

bakunin
# 3  
Old 10-22-2007
Quote:
Originally Posted by bakunin
In principle this is easy (replace "<b>" by a literal blank):

's/[^<b>]\{10\}/&<b>/g'

But i take it from your example that the substitution should only take place in the middle of a line leaving the other fields intact:

input:
NotToBeChanged 01234567890123456789 NotToBeChanged

output:
NotToBeChanged 0123456789 0123456789 NotToBeChanged

It depends on the structure of your input file how to refine the regexp then. In your example my solution would work because the first field is less than 10 characters long. If you have trouble with it pls come back here.

bakunin

Dear Bakunin
it works for that separating 10 characters but it also starts counts space as characters
so see the result came like
P2123 DRGYIQM THLNKAKTAL GFLLWIVCWA DLFYSFWER

so this output is showing with the space as counted so it affects others So,may be have to ignore the space so sed '/^$s/d' filename
so it is ok then plz incorporate fully with that earlier script

So as output shud be like
P2123 DRGYIQMTHL NKAKTALGFL LWIVCWADLF YSFWER

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove characters and replace with space

tr -cd '\11\12\15\40-\176' < file-with-binary-chars > clean-file This removes special characters but how can I replace it with space (4 Replies)
Discussion started by: eskay
4 Replies

2. Shell Programming and Scripting

How to separate sorte different characters from one textfile and copy them in a new textfile?

My first post, so don't kill me :) Say i open some textfile with some example like this. on the table are handy, bread and wine Now i know exactly what is in and i want to separate and sorted it in terminal to an existing file with another 2 existing lines in like this: table plane ... (3 Replies)
Discussion started by: schwatter
3 Replies

3. Shell Programming and Scripting

[Solved] How to separate one line to mutiple line based on certain number of characters?

hi Gurus, I need separate a file which is one huge line to multiple lines based on certain number of charactors. for example: abcdefghi high abaddffdd I want to separate the line to multiple lines for every 4 charactors. the result should be abcd efgh i hi gh a badd ffdd Thanks in... (5 Replies)
Discussion started by: ken6503
5 Replies

4. Shell Programming and Scripting

Help awk/sed: putting a space after numbers:to separate number and characters.

Hi Experts, How to sepearate the list digit with letters : with a space from where the letters begins, or other words from where the digits ended. file 52087mo(enbatl) 52049mo(enbatl) 52085mo(enbatl) 25051mo(enbatl) The output should be looks like: 52087 mo(enbatl) 52049... (10 Replies)
Discussion started by: rveri
10 Replies

5. Shell Programming and Scripting

Add a space between certain characters Using Perl Scripting

Hello All, I have a variable which is having values like this.. $var=A,B,C,D,E,F,G,H I want to add space after every three alphabets so that my final variable should look like this.. $var=A,B,C, D,E,F, G,H the space should come after the comma of third alphabet.. Pls tell me... (3 Replies)
Discussion started by: smarty86
3 Replies

6. Shell Programming and Scripting

Insert space between characters using sed

Input: Youcaneasilydothisbyhighlightingyourcode. Putting space after three characters. You can eas ily dot his byh igh lig hti ngy our cod e. How can i do this using sed? (10 Replies)
Discussion started by: cola
10 Replies

7. Shell Programming and Scripting

escape space characters in loop from file

Hi Everyone! I want to build sql inserts from a list of countries/regions saved in a file. The list looks like this: United Kingdom Czech Republic ... The script I run is: while read i; do var=`expr $var + 1`; echo "INSERT INTO calltypes VALUES($var, '$i','$i');" >>... (5 Replies)
Discussion started by: linuca
5 Replies

8. Shell Programming and Scripting

remove space characters

hello I have this output ifspeed 100000000 ifspeed 100000000 collisions 413 collisions 10 duplex full duplex ... (1 Reply)
Discussion started by: melanie_pfefer
1 Replies

9. UNIX for Dummies Questions & Answers

wc of characters in a file ignoring white space

Hi everyone, $ more abcdefg.ksh abcdef alpha beta gamma abcdef abcdef lmnop $ wc sachin1.ksh 5 7 132 abcdefg.ksh if you see it shows that file has got 240 characters. I actually want to count how many characters... (1 Reply)
Discussion started by: sachin.gangadha
1 Replies

10. UNIX for Dummies Questions & Answers

separate information with a space character

Hi, I would like to display a sorted list (based on the login name) of the login name, the home directory and the default shell of each user defined on the system ; I just do cut -d: -f1,6,7 /etc/passwd | sort And then I would like to separate each information with a space... (2 Replies)
Discussion started by: remid1985
2 Replies
Login or Register to Ask a Question