Replace pipe delimited column string to null

Hi All,

I have a large dat file where each lines are pipe delimited values. I need to parse the file depending on the request. For example: sometimes I have told to remove all the values in the 7th column (this case remove values '3333' only from the first line and '3543' from the second line) from the file. As the file contains thousands of lines, I need to find a way that can be done easily. I know it can be done by sed or perl but with my limited knowledge I am not able to figured it out.

Note that from time to time I need to remove values from nth column.

Input:

123456|ABC|Y||89575|456.7|3333|2014||A|
465273|SDE||N|46238||3543|1923|X|N|

Output:

123456|ABC|Y||89575|456.7||2014||A|
465273|SDE||N|46238|||1923|X|N|

Any help is greatly appreciated!

Is this a homework assignment?

No...
This is part of a work that I am trying to build at work so that I don't have to do it manually. I need it badly. :frowning:

num=5
awk -vcol=$num -F"|" '{$col=""}1' OFS="|" filename
1 Like

Hi Pravin,

thank you very much. your solution works perfectly.