add comma


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers add comma
# 1  
Old 10-18-2002
Lightbulb add comma

I have a file like this

101223345
23232344a
1312a3441
903821224
143434324
101223345
23232344a
1312a3441

I want to insert comma in 5 digit.
it should be like
10122,3345
23232,344a

how can I do this ?

thanks
Alice...
# 2  
Old 10-18-2002
sed 's/\(^.....\)/\1,/' < input > output
# 3  
Old 10-18-2002
try this...

for i in `cat yourfile`
do
col1=`echo $i | cut -b1-5`
col2=`echo $i | cut -b6-`
echo $col1 ',' $col2
done

there will be more straight forward way than this... and I will love to see that...

Smilie
# 4  
Old 10-18-2002
I got the answer I wanted!

correct me if I'm wrong... here Perderabo used sed with a tagged regular expression

\(^.....\) -- this will tag the first 5 characters in the input string

\1, -- \1 refers the above tagged 5 characters and just put a , after that...

this is elegant...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add previous text when replacing comma with new line

Hi, I've got this output: # cat test2.txt TM1ITP1-TMNLSTP1 SLC00=0,SLC01=0,SLC02=0,SLC03=0 if I just use cat test2.txt | tr "," "\n" I'll end up very near to what I'm trying to achieve: TM1ITP1-TMNLSTP1 SLC00=0 SLC01=0 SLC02=0 SLC03=0 But how can i eventually add the term... (1 Reply)
Discussion started by: nms
1 Replies

2. Shell Programming and Scripting

awk to parse comma separated field and removing comma in between number and double quotes

Hi Experts, Please support I have below data in file in comma seperated, but 4th column is containing comma in between numbers, bcz of which when i tried to parse the file the column 6th value(5049641141) is being removed from the file and value(222.82) in column 5 becoming value of column6. ... (3 Replies)
Discussion started by: as7951
3 Replies

3. Shell Programming and Scripting

sed add double quotes and comma

Hi, 00000119EEEC3F25 feedoor 20171103 0000011A4F152077 feedard 20171024 00000191FA295F61 feedzipperhola 20171023 00000213C57BB856 feedriodapple 20171005 0000025F778EF9D5 joobakoolrk 20171004 I needed the result as: "00000119EEEC3F25", "feedoor", ... (9 Replies)
Discussion started by: ashokvpp
9 Replies

4. UNIX for Dummies Questions & Answers

Add a field separator (comma) inside a line of a CSV file

Hi... I can't find my little red AWK book and it's been a long while since I've awk'd. But I need to take a CSV file and convert the first word of the fifth field to its own field by replacing a space with a comma. This is for importing a spreadsheet of issues into JIRA... Example: a line... (9 Replies)
Discussion started by: Tawpie
9 Replies

5. Shell Programming and Scripting

Use sed to add comma to end of first field

Example data Gi1/10 Gi1/12 xl32lytscb07 3/11 to nyc 3/12 41764 ecomm 3/13 hxcsxsa 2/1 3/14 ziim570-rsvd 3/15 xl3NDSADM Po1 VPC trunk to xl3-i Po2 ***DO NOT ENABLE** Po13 *** VPC link to Po101 Po102 xl3-2lyg1accsgh-fe... (7 Replies)
Discussion started by: sumguy
7 Replies

6. UNIX for Dummies Questions & Answers

How to add comma after every value in a array

Hi all Requirement: I need to generate a comma seperated file(.csv) I have one functions which returns me some values in a array. Now i want to add comma after every value that gets stored in the array. E.g: arr=$var1"," Expected: arr=abc, arr=def, . . likewise thanks in advance... (4 Replies)
Discussion started by: Ganesh_more
4 Replies

7. Shell Programming and Scripting

Need Help - comma inside double quote in comma separated csv,

Hello there, I have a comma separated csv , and all the text field is wrapped by double quote. Issue is some text field contain comma as well inside double quote. so it is difficult to process. Input in the csv file is , 1,234,"abc,12,gh","GH234TY",34 I need output like below,... (8 Replies)
Discussion started by: Uttam Maji
8 Replies

8. Shell Programming and Scripting

Convertin IP adresses from a column to a raw + add a comma between addresses

Hi all, I have a list of IP addresses in a column in a text file name ipaddress.txt 192.168.0.1 192.168.0.2 192.168.0.5 192.168.0.4 192.168.0.5 I would like to convert ipaddress.txt to have the following thing : 192.168.0.1, 192.168.0.2, 192.168.0.3,192.168.0.4,192.168.0.5 I know... (4 Replies)
Discussion started by: oliv66
4 Replies

9. UNIX for Dummies Questions & Answers

Add comma to integer using AWK

Srr for being pain her let say i have a data in a file like this 1@1000 2@2000 4@4000 5@7770 6@8998 7@80008 i am a newbie in Unix i need to add a comma to integer using AWK function. for example, 1,000 or 80,008 how can i do that ps. i'm using bash shell (1 Reply)
Discussion started by: Nutter
1 Replies

10. Shell Programming and Scripting

Add a comma at end of every line

hello A small shell scripting help.. I have a file say with 5 lines of text (text file). At the end of everyline I need to add a comma at the end of the file. Thanks, ST2000 (4 Replies)
Discussion started by: ST2000
4 Replies
Login or Register to Ask a Question