Issue
I have a header and what to add the prefix "f4_" to each column.
I tried this:
echo -e p.value"\t"beta | sed "s/\</f4_/g"
and got this:
f4_p.f4_value f4_beta
I want this:
f4_p.value f4_beta
I think the special character . in the header is messing this up but I am not sure how to fix
Solution
You can try this awk
:
printf 'p.value\tbeta\n' |
awk 'BEGIN{FS=OFS="\t"}
{for (i=1; i<=NF; ++i) ($i != "") && $i = "f4_" $i} 1'
f4_p.value f4_beta
For a no loop solution suggest you to use this gnu-awk
solutiom:
printf 'p.value\tbeta\n' |
awk -v RS='[\t\n]+' 'NF{$0 = "f4_" $0} {ORS=RT} 1'
f4_p.value f4_beta
Answered By - anubhava Answer Checked By - David Goodson (WPSolving Volunteer)