Manan Shah
Manan Shah

Reputation: 1098

Replace everything between two character

All.

I am newbie to sed.

I want something like

Input:

ABC,DEF,GHI,JKL,MNO

Output:

ABC,,,,MNO

Means....

I want to remove all contents between two ','

Upvotes: 1

Views: 125

Answers (2)

Kent
Kent

Reputation: 195029

you could set all fields between 1 and last to empty with awk:

awk -F, -v OFS="," '{for(i=2;i<NF;i++)$i=""}7'

Upvotes: 3

potong
potong

Reputation: 58371

This might work for you (GNU sed):

sed 's/[^,]*,/,/2g' file

Upvotes: 5

Related Questions