Reputation: 1726
Let say i have input line:
input:
{x:y} abc det uyt llu
how to process it, to get expected output:
output:
{x:y} abc%det%uyt%llu
Question is how to concatanate fields 2-end of line, and in that string change space with % where separator is space
I need fixed first part {x:y} and implementing pipe for fields 2-end of line
Upvotes: 1
Views: 119
Reputation: 41456
Here is another awk
awk '{$1=$1;sub(/%/," ")}1' OFS="%" file
echo '{x:y} abc det uyt llu' | awk '{$1=$1;sub(/%/," ")}1' OFS="%"
{x:y} abc%det%uyt%llu
This change all space to %
, using OFS
and $1=$1
, then change the first %
to space.
Upvotes: 2
Reputation: 785246
You can use this awk:
s='{x:y} abc det uyt llu'
awk '{printf "%s%s", $1, OFS; for (i=2; i<=NF; i++) printf "%s%s", $i, (i==NF)?RS:"%"}' <<< "$s"
{x:y} abc%det%uyt%llu
Another awk:
awk '{printf "%s%s", $1, OFS; OFS="%"; $1=""; print substr($0, 2)}' <<< "$s"
{x:y} abc%det%uyt%llu
Upvotes: 1