Reputation: 825
I am using following line to write some data to the file:
cat $srcfile | awk -v p=$prefix '{printf("XX_%s%s XX_%s\n", p, $1, $1);}' > $dstfile
How can I change XX by two first letters of $1?
Upvotes: 0
Views: 49
Reputation: 88553
With substr
:
echo "abcdef 12345" | awk -v p="foo" '{x=substr($1,1,2); printf("%s_%s%s %s_%s\n", x, p, $1, x, $1);}'
Output:
ab_fooabcdef ab_abcdef
Upvotes: 2