insert delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting insert delimiter
# 8  
Old 06-24-2011
Quote:
Originally Posted by Corona688
[edit] Figured it out! You're not splitting it in chunks, you're adding , in front of select characters. Neat.
Smilie

I was going to add behind but this way was easier than dealing with the trailing comma.

edit: i only used the regex because a simple "$i" as the for test didn't work. "i < NF" might be faster.

Code:
root@wrtu54g:~# echo 20110624000744000693000704000764 | awk -v FS= -v OFS= '{for
(i=9;i<NF;i+=6)$i=","$i}1'
20110624,000744,000693,000704,000764

i'm learning myself by trying to help on the forums. is why i've been posting somewhat too frequently lately..

Last edited by neutronscott; 06-24-2011 at 11:02 PM..
# 9  
Old 06-24-2011
Code:
echo 20110624000744000693000704000764 |perl -nle'print join ",",unpack "A8(A6)*"'
20110624,000744,000693,000704,000764
echo 20110624000744000693000704000764 |perl -pe'pos=8;s/\G.{6}/,$&/g'
20110624,000744,000693,000704,000764


Last edited by binlib; 06-24-2011 at 11:48 PM..
This User Gave Thanks to binlib For This Post:
# 10  
Old 06-28-2011
If it is garbled I dont care it works great! Thanks

$ echo 20110624000744000693000704000764 | sed "s/.\{8\}/&,/;s/[^\,]\{6\}/&,/g;s/,//"
20110624,000744,000693,000704,000764,

Quote:
Originally Posted by scottn
I got a bit close with this:

Code:
$ sed "s/.\{8\}/&,/;s/[^\,]\{6\}/&,/g;s/,//" file1
20110624,000744,000693,000704,000764,

That's a garbled command - if ever I saw one! - even if SED didn't report it this time Smilie

I suppose, "garbling" a bit more, adding ;s/,$// at the end would fix it!
Code:
20110624,000744,000693,000704,000764

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert a value between two empty delimiter in the file.

Would like to insert value between two empty delimiter and at the very last too if empty. $ cat customerleft.tbl 300|Customer#000000300|I0fJfo60DRqQ|7|17-165-193-5964|8084.92|\N|p fluffily among the slyly express grouches. furiously express instruct||||||||||||||||||||||||\N... (3 Replies)
Discussion started by: Mannu2525
3 Replies

2. Shell Programming and Scripting

Linux shell script to insert new lines based on delimiter count

The input file is a .dat file which is delimited by null (^@ in Linux). On a windows PC it looks something like this (numbers are masked with 1). https://i.imgur.com/nta2Gqp.jpg The entire file is in one row but it has multiple records - each record contains 80 fields i.e. there are 81 counts... (9 Replies)
Discussion started by: digitalnirvana
9 Replies

3. Shell Programming and Scripting

Insert a new column with sequence number (Delimiter as comma)

Hi All, I have a file which has data like a,b c,d e,f g,h And I need to insert a new column at the begining with sequence no( 1 to n) 1,a,b 2,c,d 3,e,f 4,g,h Please let me know how to acheive this in unix (3 Replies)
Discussion started by: weknowd
3 Replies

4. Shell Programming and Scripting

[Solved] Insert tabs as delimiter

Hello all, I have an unstructured file with space as delimiter , which I want to structure. The output file should actually have only 5 columns with tab as delimiter. The 4th column can have only 3 values ( biological_process , cellular_component , molecular_function ) Here is how the... (12 Replies)
Discussion started by: ritakadm
12 Replies

5. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

6. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

7. Shell Programming and Scripting

Selecting Specific Columns and Insert the delimiter TAB

Hi, I am writing a Perl Script for the below : I have a data file that consists of the header information which is 231 Lines and the footer information as 4 lines. The total number of line including the header and footer 1.2 Million with Pipe Delimited file. For example: Header Information:... (4 Replies)
Discussion started by: filter
4 Replies

8. UNIX for Advanced & Expert Users

Insert Delimiter at fixed locations in a flat file

Hi Can somebody help me with solution for this PLEASE? I have a flat file and need to insert delimiters at fixed positions in all the lines so that I can easily convert into EXCEL with columns defined as per their width. For Example Here is the file { kkjhdhal sdfewss sdtereetyw... (7 Replies)
Discussion started by: jd_mca
7 Replies

9. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

Hi, I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies

10. Shell Programming and Scripting

Insert text between delimiter

Can someone help me on this? I'm creating an Insert stmt script but Oracle does not accept blanks values. How can I insert the word null between two commas? I'm guessing awk or sed. Is there a good post or site with easy to understand info on awk and sed? I'm really new to unix scripts :D ... (5 Replies)
Discussion started by: ystee
5 Replies
Login or Register to Ask a Question