Find certain number of character in vi


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find certain number of character in vi
# 1  
Old 03-26-2012
Find certain number of character in vi

Hello, Experts,

I have a file with the first and second column connected together, and i want to use vi to seperate them (put a space in between).

Is there any command in vi would put a space after the 7th letter?

Thanks!

example:
0.981101.517
2.944101.517
4.907101.517
# 2  
Old 03-26-2012
In VI:
Code:
:%s/......./& /

(after the 7th character, giving...)
Code:
0.98110 1.517
2.94410 1.517
4.90710 1.517

Please show the expected output if that is off the mark!
# 3  
Old 03-26-2012
This will do it. But it will also change other columns and put extra two lines of 0.0000 after each line.

One more question, what is & do in the command, does that mean after the pattern I searched, keep the pattern and add things?

Thanks.
# 4  
Old 03-26-2012
Yes, & is the matched pattern (seven characters).

I don't understand your first point. This only adds a space after the first seven characters in each line. Nothing else.
# 5  
Old 03-26-2012
0.981101.517 0.4385 0.1625 0.5312 0.1108 0.1038 0.0142
2.944101.517 0.4815 0.1263 0.4148 0.1724 0.0928 0.0321
4.907101.517 0.4736 0.0343 0.3402 0.0970 0.0829 0.0077
6.870101.517 0.6628 0.2186 0.7098 0.2266 0.0000 0.0000


this is actually what is before

and after

0.981 101.517 0. 4385 0.1625 0. 5312 0.1108 0. 1038 0.0142
2.944 101.517 0. 4815 0.1263 0. 4148 0.1724 0. 0928 0.0321
4.907 101.517 0. 4736 0.0343 0. 3402 0.0970 0. 0829 0.0077
6.870 101.517 0. 6628 0.2186 0. 7098 0.2266 0. 0000 0.0000


sorry, my mistake. it did not put extra two 0.0000 there. I looked wrong. but it did changed the structure of the later column.
# 6  
Old 03-26-2012
I don't see how, unless you added the g modifier

i.e.

Code:
%s/...../& /g


Last edited by Scott; 03-26-2012 at 01:48 PM.. Reason: It wasn't wrong
This User Gave Thanks to Scott For This Post:
# 7  
Old 03-26-2012
so after i used the command, the 0.4385 became 0. 4385, one more space between them. i guess if i do this, it might work.
:%s/^......./& /

---------- Post updated at 11:49 AM ---------- Previous update was at 11:48 AM ----------

Thank you so much~ it worked!
 
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 string between number and character

hello ! I have to remove string between a number and set of characters. For example, 35818 -stress - - -stress - - - - - - DB-3754 44412 caul kid notify DB-3747 54432 roberto -, notify DB-3725 55522 aws _ _int _ _classified 2_a _a 2_m _m 2_classified 2_search... (7 Replies)
Discussion started by: ManoharMa
7 Replies

2. Shell Programming and Scripting

awk or other way to find out number of occurrence of 7th character

Hi all, I am looking for to filter out based on 7th character and list the number of occurrence based on the 7th character if p , d , o or m 1. if 7th character is p , Output should be: p_hosts = N 2. if 7th character is d , Output should be: d_hosts = N 3. if 7th character is o , Output... (10 Replies)
Discussion started by: rveri
10 Replies

3. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

4. Shell Programming and Scripting

awk command to find total number of Special character in a column

How to find total number of special character in a column? I am using awk -f "," '$col_number "*$" {print $col_number}' file.csv|wc -l but its not giving correct output. It's giving output as 1 even though i give no special character? Please use code tags next time for your code and... (4 Replies)
Discussion started by: AjitKumar
4 Replies

5. Shell Programming and Scripting

Find character and Replace character for given position

Hi, i want find the character '-' in a file from position 284-298, if it occurs i need to replace it with 'O ' for the position in the file. How to do that using SED command. thanks in advance, Sara (9 Replies)
Discussion started by: Sara183
9 Replies

6. Shell Programming and Scripting

new line after specific number character

Hi All, I have input file like this: input1: ( 1083479)=T 158V 1798, T 391V 1896,T 1138V 2273,T 1547V 2477,T 2249V 2917,T 3278V 3234,T 4152V 3495,T 5500V 3631, ( 1083501)=T 181V 1851, T 459V 1954,T 810V 2141,T 1188V 2372,T 1638V 2696,T 2731V 3124,T 4799V 3640,... (5 Replies)
Discussion started by: attila
5 Replies

7. Shell Programming and Scripting

Count number of occurences of a character in a field defined by the character in another field

Hello, I have a text file with n lines in the following format (9 column fields): Example: contig00012 149606 G C 49 68 60 18 c$cccccacccccccccc^c I need to count the number of lower-case and upper-case occurences in column 9, respectively, of the... (3 Replies)
Discussion started by: s052866
3 Replies

8. Shell Programming and Scripting

check number of character

hi, I would like to calculate number of character for a number, for exemple : 1200 --> there are 4 characters , 120001 -> 5 characters (4 Replies)
Discussion started by: francis_tom
4 Replies

9. Shell Programming and Scripting

Putting new line after certain number of character

Hi, I want, if a line is more than 80 characters length then put a new line with 4 space after each 80 characters to indent the data at same position. Input: 200 Geoid and gravity anomaly data of conjugate regions of Bay of Bengal and Enderby Basin: New constraints on breakup and early... (3 Replies)
Discussion started by: srsahu75
3 Replies

10. Shell Programming and Scripting

Number or Character

How to find that a given variable is a number or character? e.g. echo "Enter the number" read var If "$var" is a number then display "Number has been entered" else display "Character has been entered". Thanking you in advance (3 Replies)
Discussion started by: j1yant
3 Replies
Login or Register to Ask a Question