Reputation: 23
I was trying to do the following.
I was trying to put column 1 when I found a pattern that would be "undefined", for example:
I have my file.txt file that contains
192.168.1.1, Paul
192.168.2.2, undefined
Here it is "undefined", then replace it with the first column in the row where it is "undefined". (192.168.2.2)
192.168.1.1, Paul
192.168.2.2, 192.168.2.2
Can somebody help me?
Upvotes: 0
Views: 856
Reputation: 195229
This line works for your example, no matter the separator is ,
or ,(space)
awk -F, '1+sub(/undefined$/,$1)' file
Upvotes: 0
Reputation: 13259
You can use sed
:
sed 's/\(.*\), undefined$/\1, \1/' file.txt
or
sed -r 's/(.*), undefined$/\1, \1/' file.txt
Upvotes: 0
Reputation: 3089
using awk
$ awk -F", " '$2~/undefined/{ print $1 FS $1; next}1' file
192.168.1.1, Paul
192.168.2.2, 192.168.2.2
Upvotes: 1