Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append corresponding lines of two files 1

Status
Not open for further replies.

neuralnode

Technical User
Sep 12, 2007
59
PL
Hi All,

I've been meditating in a remote cave for a thousand years over the following problem.

I have two files.
File param_list contains:

/dev/ip ip_forward_src_routed
/dev/ip ip_respond_to_timestamp
/dev/tcp tcp_rev_src_routes

(please note there is a blank space after /dev/ip)

File param_values contains, e.g.:

0
1
2048


Now what I'm trying to accomplish is to create a third text file with corresponding lines appended, which should look like:

/dev/ip ip_forward_src_routed 0
/dev/ip ip_respond_to_timestamp 1
/dev/tcp tcp_rev_src_routes 2048


I guess I'll have to use "read" within a while loop, like:

while read -r listline
do
read -r valline < param_values
echo "${line} ${pline}"
done < param_list


But it doesn't work. Maybe some awk or sed expression would help?

Any ideas?

Thx
 
One way:
Code:
awk 'NR==FNR{p[NR]=$0;next}{print p[FNR],$0}' param_list param_values

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Works like a charm!
Thanx!

(I'm leaving my cave now.)

--
 
I know this is an awk forum, BUT...

since it is on a unix-like system, how about

[tt]
paste -d' ' param_list param_values
[/tt]

?



HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top