Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

awk -cut how to delete second column with field separator

Tags:

bash

sed

awk

I have a csv file with data presented as follows

'&(||o||022344527||o||lonyfoe||o||Joe||o||Joe||o||Otieno

I'm trying to delete second column.

Output :

'&(||o||lonyfoe||o||Joe||o||Joe||o||Otieno

Any ideas?

This is what I have tried so far

cut -d'||o||' -f2 --complement 

awk -F'||o||' '{
   for(n=1; n<=NF; n++){
      if(n!=NF)fmt="%s|"; else fmt="%s\n"
      if(n!=2)printf(fmt,$n)
   }
}' 

but it doesn't work

like image 725
Dr Jay Avatar asked Jan 29 '23 15:01

Dr Jay


1 Answers

If your Input_file is same as shown sample then following may help you on same:

awk '{sub(/\|\|o\|\|[0-9]+\|\|o\|\|/,"||o||")} 1'  Input_file

Output will be as follows:

'&(||o||lonyfoe||o||Joe||o||Joe||o||Otieno
like image 166
RavinderSingh13 Avatar answered Feb 01 '23 14:02

RavinderSingh13