technopathe
technopathe

Reputation: 107

Remove first columns delimiter

I have a CSV file with ; delimiter:

3;85;2;8;9;5;8;6
7;4;5;6;2;2;4;6

I would like to have this output:

38528;9;5;8;6
7456;2;2;4;6

In general, I am trying to remove the delimiter from the three first columns.

Upvotes: 0

Views: 138

Answers (6)

karakfa
karakfa

Reputation: 67507

hacky version of removing first three column delimiters:

sed -f <(echo "s/;//;"{,,}) file

Upvotes: 1

RavinderSingh13
RavinderSingh13

Reputation: 133518

try:

sed 's/;//1;s/;//1;s/;//1'   Input_file

substitute semi colon on first position, then do the same operation 2 more times because one it will be done for example first position then second occurrence will become first semi colon then.

Upvotes: 0

Ed Morton
Ed Morton

Reputation: 203532

$ awk '{for(i=1;i<4;i++)sub(/;/,"")}1' file
38528;9;5;8;6
7456;2;2;4;6

Upvotes: 1

Benjamin W.
Benjamin W.

Reputation: 52142

In sed:

$ sed -E 's/([^;]*);([^;]*);([^;]*);/\1\2\3/' infile
38528;9;5;8;6
7456;2;2;4;6

This looks for and captures the pattern "a sequence of non-semicolons" followed by a semicolon, three times, and substitutes by the captured sequences not containing the semicolons.

Upvotes: 1

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89557

With sed:

sed 's/;//;s/;//;s/;//' file

(replace ; with nothing, 3 times)

Upvotes: 2

luoluo
luoluo

Reputation: 5533

awk approach

awk 'BEGIN{FS=OFS=";"} {print $1$2$3$4,$5,$6,$7,$8}' input_file
38528;9;5;8;6
7456;2;2;4;6

Upvotes: 3

Related Questions