2

The left part data (in variable) like :

 echo "$lpart"

 "2017-07-03 13:39:5", "-39dB", "7c:e9:d3:f1:61:55"
 "2017-07-03 13:39:5", "-39dB", "7c:e9:d3:f1:61:55"
 "2017-07-03 13:39:5", "-39dB", "7c:e9:d3:f1:61:55"
 "2017-07-03 13:39:5", "-37dB", "7c:e9:d3:f1:61:55"

The right part data (in variable) like :

echo "$rpart"     

"qhy2"
"qhy2"
"Apple Setup"
"qhy2"

I would like to merge the 2 data by column, it is :

 "2017-07-03 13:39:5", "-39dB", "7c:e9:d3:f1:61:55"  "qhy2"
 "2017-07-03 13:39:5", "-39dB", "7c:e9:d3:f1:61:55"  "qhy2"
 "2017-07-03 13:39:5", "-39dB", "7c:e9:d3:f1:61:55"  "Apple Setup"
 "2017-07-03 13:39:5", "-37dB", "7c:e9:d3:f1:61:55"  "qhy2"

This request is the same as the post : how to combine two variable column-by-column in bash, but my busybox does not support paste command. I have tried the commands :

 awk 'BEGIN{print ARGV[1], ARGV[2]}' "$lpart"  "$rpart"
 awk -v awk_lpart="$lpart" -v awk_rpart="$rpart" 'BEGIN{print awk_lpart awk_rpart }'

those will merge by row..

Could you give me suggestion how I could achieve the request ? Thank you.

2 Answers 2

1

Using awk you can do this:

awk 'NR==FNR {a[FNR]=$1; next} {print $0, a[FNR]}' <(echo "$rpart") <(echo "$lpart")
"2017-07-03 13:39:5", "-39dB", "7c:e9:d3:f1:61:55" "qhy2"
"2017-07-03 13:39:5", "-39dB", "7c:e9:d3:f1:61:55" "qhy2"
"2017-07-03 13:39:5", "-39dB", "7c:e9:d3:f1:61:55" "Apple
"2017-07-03 13:39:5", "-37dB", "7c:e9:d3:f1:61:55" "qhy2"
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, that is, the braces {} would respond to the introduced(<) data respectively ?
<(...) is process substitution. You must use bash for this.
Thank your suggestion, it works. Is the way for multi-variables also?
You can insert 2 variables at a time and then save the output in a new variable. After that you can run same awk command between new variable and 3rd var.
1

Building on one of your attempts:

awk -v awk_lpart="$lpart" -v awk_rpart="$rpart" 'BEGIN{
    split(awk_lpart,lp,/\n/)
    split(awk_rpart,rp,/\n/)
    for (i=1; i in lp; i++) {
        print lp[i], rp[i]
    }
}'
"2017-07-03 13:39:5", "-39dB", "7c:e9:d3:f1:61:55" "qhy2"
"2017-07-03 13:39:5", "-39dB", "7c:e9:d3:f1:61:55" "qhy2"
"2017-07-03 13:39:5", "-39dB", "7c:e9:d3:f1:61:55" "Apple Setup"
"2017-07-03 13:39:5", "-37dB", "7c:e9:d3:f1:61:55" "qhy2"

That will work with any awk in any shell on any UNIX box.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.