J
J
JJa2020-11-11 20:48:26
linux
JJa, 2020-11-11 20:48:26

How to replace a character in a string in BASH?

There is a document (text.csv) that contains lines in the format 1*2*3*4*5. I want to fulfill the condition, if the value in column 4 is different from 0, then replace it with 1.
I wanted to do something like: cat text.csv | awk '{if ($4!=0) and here's a replacement}'.

Help me figure it out please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2020-11-11
@JJa

awk 'BEGIN{OFS=FS="*"}$4!=0{$4=1}{print}' text.csv

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question