Place a comma on lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Place a comma on lines
# 1  
Old 12-19-2008
Place a comma on lines

Is it possible to place a comma in the desired places, like 10spaces after or 15 spaces after, irrespective of the contents???

Ex:File: TEST

TEST:

vimalthomaswants to place a comma
can he do it in the desired places?

as per the above file, i need to place a comma after 10th space irrespetive of the content can i do this??

Expected output:

vimalthoma,swants to place a comma
can he do i,t in the desired places?
# 2  
Old 12-19-2008
Hi,

try:

Code:
sed 's/^\(.\{10\}\)\(.*\)/\1,\2/' file

HTH Chris
# 3  
Old 12-19-2008
It works well thanks a lot
can u explain the same?? and how can i bring commas in different places at a time

like "vimal,thomas,wants to know,"
# 4  
Old 12-19-2008
Code:
sed 's/^\(.\{10\}\)\(.*\)/\1,\2/' file

s/a/b/ -- substitute a with b
^ -- beginning of a line
.\{10\} -- "." matches anything, \{10\} ten occurences of "."
\(...\) -- saves the match in the registers \1 to \9

Thus to add a comma after the 10th, 20th and 30th charachter.

Code:
sed 's/^\(.\{10\}\)\(.\{10\}\)\(.\{10\}\)\(.*\)/\1,\2,\3,\4/' file

HTH Chris
# 5  
Old 12-19-2008
Thank you sir... It is really rocking!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Lines with comma

I have file which contains line with only comma and text separated by comma. a.txt contain a,ab,ac ,, b,bc,bd ,, ,, c,cd,ce need to print only line 2, 4, and 5 because they only contain comma and no text. I need an unix command to find out. thanks in advance Please do wrap... (5 Replies)
Discussion started by: pranabpal
5 Replies

2. Shell Programming and Scripting

Comma separated values to individual lines

My OS : RHEL 6.7 I have a text file with comma separated values like below $ cat testString.txt 'JOHN' , 'KEITH' , 'NEWMAN' , 'URSULA' , 'ARIANNA' , 'CHENG', . . . . I want these values to appear like below 'JOHN' , 'KEITH' , 'NEWMAN' , 'URSULA' , 'ARIANNA' , 'CHENG', .... (4 Replies)
Discussion started by: kraljic
4 Replies

3. Shell Programming and Scripting

Need to merge multiple text files vertically and place comma between fields

Hello expert friends, I'm writing a script to capture stats using sar and stuck up at report generation. I have around 10 files in a directory and need to merge them all vertically based on the time value of first column (output file should have only one time value) and insert comma after... (6 Replies)
Discussion started by: prvnrk
6 Replies

4. Shell Programming and Scripting

Find regex, place on individual lines and insert blank line before

Hello, I have a file that I want to be able to insert a new line before every instance of a regex. I can get it to do this for each line that contains the regex, but not for each instance. Contents of infile: Test this 1... Test this 2... Test this 3... Test this 4... Test this... (2 Replies)
Discussion started by: deneuve01
2 Replies

5. Shell Programming and Scripting

Insert comma in place of column

Hi all, I have a file in which I have to insert commna between entries of 2 column and createa new file separated by commas not a columns if input is FHIT Adenosine Monotungstate Not Available CS Trifluoroacetonyl Coenzyme A Not Available Theo expected output is ... (5 Replies)
Discussion started by: manigrover
5 Replies

6. Shell Programming and Scripting

How to get awk to edit in place and join all lines in text file

Hi, I lack the utter fundamentals on how to craft an awk script. I have hundreds of text files that were mangled by .doc format so all the lines are broken up so I need to join all of the lines of text into a single line. Normally I use vim command "ggVGJ" to join all lines but with so many... (3 Replies)
Discussion started by: n00ti
3 Replies

7. Shell Programming and Scripting

Find a string and place two blank lines

Hi friends, I am looking for a line to find a particular string in my file and once found then replace with 2-3 blank lines before the string Example: aaa 11 bbb 1 2 3 aaa 22 bbb 4 5 6 Output (4 Replies)
Discussion started by: shaliniyadav
4 Replies

8. Shell Programming and Scripting

extract x lines after a pattern - place each result in separate file

Hi all, I have many files that have 1 or more occurrences of the information I want. There are two distinct sets of information. I want get this info and place each occurrence in its own file. The 3 lines before one set are this grid 00 01 02 16 17 18 **40 lines of code I want to... (5 Replies)
Discussion started by: gobi
5 Replies

9. Shell Programming and Scripting

Joining three lines with comma separation

I have a file that looks like this: G. KRESSLAR 9618 W. APPALOOSA DRIVE SUN CITY, AZ 85373 SHIRLEY ALLEN 7272 W. VIA MONTOYA DRIVE GLENDALE, AZ 85310 LOUIS VALDEZ 244441 N. 86TH AVENUE PEORIA, AZ 85383 DONNA NEWBON 3231 W. DENTON #D PHOENIX, AZ 85017 SARAH WILSON 6534 W. PALO... (3 Replies)
Discussion started by: BCarlson
3 Replies

10. Shell Programming and Scripting

adding lines at special place in crontab

Hi , i export the crontab in a file (i've no root right) and i would add lines from a file at a special place and rewrite the output in an another file. the special place is as this : 45 04 * * * /home/toto.sh > /dev/null 2>&1 # so i would search for toto.sh and insert the lines , the... (5 Replies)
Discussion started by: Nicol
5 Replies
Login or Register to Ask a Question