Reputation: 99
What's wrong with my syntax here?
awk -F '|' 'sub/\s*\w*/,"Visit our website!","$3"' merchant_report
it's suppose to turn
|bob|jones| blagblag| texas
|tom|markus| | alabama
into
|bob|jones|Visit our website!| texas
|tom|markus| | alabama
Upvotes: 0
Views: 49
Reputation: 85865
In awk
you would just assign the field the new value for the given line. If you are more comfortable with the substitution approach try sed
:
sed '1s/|[^|]*/|Visit our website!/3' file
|bob|jones|Visit our website!| texas
|tom|markus| | alabama
Upvotes: 0
Reputation: 195209
this line may do what you want:
awk -F'|' -v OFS="|" 'NR==1{$4="Visit our website!"}1' file
in your awk codes:
FS
to separate the fields, you don't need the sub
func., just set $3
directly.sub( )
function, your syntax is not correct. you can get detail info by man gawk
$3
, it is $4
. because your line starting with |
NR==1
otherwise awk will do the change on all linesexample with the code:
kent$ cat file
|bob|jones| blagblag| texas
|tom|markus| | alabama
kent$ awk -F'|' -v OFS="|" 'NR==1{$4="Visit our website!"}1' file
|bob|jones|Visit our website!| texas
|tom|markus| | alabama
Upvotes: 1