awk '{a=$2; sub(a, "hell"); print}' file
also works if it contains no regex special chars
this seems to do the trick otherwise
awk ' { p=substr($0, index($0, " ")); split(p, a, "[^ ]"); sub(/ +[^ ]+/, "", p); print
$1 a[1] "hell" p} '
Rudolf Sykora wrote:
Hello,
simple task.
I want to change the 2nd field on each line of a file, but preserve
the spacing of the lines.
If I do
awk '{$2="hell"; print}' file
the field gets changed, but all the spacing of the lines is gone; i.e.
any space is now just ' ' like this:
1 3 4 8
changes to
1 hell 4 8
while I need
1 hell 4 8.
Any help?
Thanks
Ruda