0

I try to remove repetitions of the same value of the first column from a CSV file without changing the other cell contents and alignment (in other columns).

My txt:

ACCIDENT EP 4 STEM PERCUS,,         42:30,         43:04,          0:34
ACCIDENT EP 4 STEM PERCUS,,         43:04,         43:16,          0:11
AICHA 1 COMPLET DECOUPE,,         27:38,         28:42,          1:03
AICHA 2 COMPLET MIX 1,,         23:21,         24:02,          0:40 

and i would like

ACCIDENT EP 4 STEM PERCUS,,         42:30,         43:04,          0:34
                         ,,         43:04,         43:16,          0:11
AICHA 1 COMPLET DECOUPE,,         27:38,         28:42,          1:03  
AICHA 2 COMPLET MIX 1,,         23:21,         24:02,          0:40 

Sorry but I have searched and no result.

It's a very long list with lot of duplicate cells. I would like to just keep the first of each. I'm on mac.

5
  • Welcome! You have not specified what should happen if the first field contains more than one character. Should it be simply removed (this would make things out of alignment) or should the characters be replaced by spaces? Also, please take a minute to read the tour page so as to familiarize yourself with the website.
    – Quasímodo
    Jul 30 '20 at 20:34
  • yess sorry . the first filed contains some word in column 1 who are repeat .i would like remove (space) the repeat word but without change the other columns.i' ve find to remove repeat word but it remove azll the line or it change the alignement...
    – Jf Viguie
    Jul 31 '20 at 9:17
  • Please notice that two fields are gone in the 2nd line (i.e., two , disappeared). I don't think that's what you want, check it out. Also, share with us what you tried. It does not matter if it failed, but we can give you a solution closer to your attempt and show you why it failed.
    – Quasímodo
    Jul 31 '20 at 11:26
  • the double commas are an empty columns for completed later...
    – Jf Viguie
    Jul 31 '20 at 12:34
  • Are all lines with the same value for the first column consecutive, or can a value found "further up" in the file reappear further down in the file, after several lines with a different value for the first column?
    – AdminBee
    Jul 31 '20 at 12:41
3
$ awk 'BEGIN{FS=OFS=","} {if ($1==p) gsub(/./," ",$1); else p=$1} 1' file
ACCIDENT EP 4 STEM PERCUS,,         42:30,         43:04,          0:34
                         ,,         43:04,         43:16,          0:11
AICHA 1 COMPLET DECOUPE,,         27:38,         28:42,          1:03
AICHA 2 COMPLET MIX 1,,         23:21,         24:02,          0:40
1
  • 1
    just perfect ! thank you ....
    – Jf Viguie
    Jul 31 '20 at 12:33
2
$ awk '$1!=last { last=$1; print; next; }; { $1=" "; print; }' input

A b c
  E R
  F T
B F T
  G 5
C T 5
  H 4
4
  • yes it's work but only for one word my first column contains multiple words...sorry my example wasn't clear...
    – Jf Viguie
    Jul 31 '20 at 9:19
  • @JfViguie Why don't you provide a usable example then? Jul 31 '20 at 10:11
  • @JfViguie You obviously should not put that in a comment. How shall anyone read that? You should correct your question. That is a general rule: If comments lead to you providing more information then it should be in the question because reading the question should be enough (and especially not misleading). Jul 31 '20 at 10:16
  • done sorry and thx
    – Jf Viguie
    Jul 31 '20 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.