2

I have a file with thousand of lines like below

32322621661395926569;adverline;www.societe.com_societe;identite;Salarie2;fiche;btp_et_construction;CA4 32322621661395926569;adverline;www.societe.com_societe;identite;Salarie2;fiche;energy;CA4;nunuc_muchemuche 

The delimiter is done with ;. I'm trying to change the delimiter after the 4th column. So every semi-colon after identite will be changed to a ,.

I've tried that

awk '$4=$4' FS=";" OFS="," filename 

but it is changing everything to a comma.

if you have any tips, I'm all ears.

1
  • Hi HuStmpHrrr, how? :) Commented Dec 22, 2014 at 14:33

2 Answers 2

7

You can specify the occurrence using sed:

sed 's/;/,/4g' file 

Results:

32322621661395926569;adverline;www.societe.com_societe;identite,Salarie2,fiche,btp_et_construction,CA4 32322621661395926569;adverline;www.societe.com_societe;identite,Salarie2,fiche,energy,CA4,nunuc_muchemuche 
Sign up to request clarification or add additional context in comments.

Comments

1

this piece of perl code should work.

#!/usr/bin/perl open FH, $filename; # fill it in while (<FH>){ my @elems = split ';', $_; push @elems, join ',', splice @elems, 3, @elems - 3; print join ';', @elems; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.