Pasting multiple files using awk with delimiter

hi,

i want to PASTE two files, with a delimiter in between, using awk and pipe the output to another file. i am able to achive the reqirement using PASTE command. but it has a limitation of length till 511 bytes.

Example:
-------
File1:
----

sam
micheal

file2:
----

bosco
jackson

Output:
--------
file3:
-----

sam~bosco
micheal~jackson
 

Thanks in Advance...

awk 'FNR==NR{a[FNR]=$0;next}{print a[FNR],$0}' OFS='~' file1 file2 > file3
1 Like

Thanks for the speedy response vgersh99

but the code gives the output
~sam
~micheal
~bosco
~jackson

but my requirement is
sam~bosco
micheal~jackson

It does work fine for me!

1 Like

Attached screenshot.

I am working in AIX, so it does work fine.

try

awk 'FNR==NR{a[FNR]=$0;next}{print a[FNR]"~"$0}' file1 file2 > file3
1 Like

What operating system are you using?

1 Like

Oracle Corporation-SunOS 5.10
(this is what is displayed when i log into UNIX)

Use nawk instead in SunOS

nawk 'FNR==NR{a[FNR]=$0;next}{print a[FNR],$0}' OFS='~' file1 file2 > file3
1 Like

and it works like majic...:slight_smile:

thanks bipinajith and everyone...:slight_smile:

---------- Post updated at 10:05 PM ---------- Previous update was at 09:47 PM ----------

Team,

Facing another issue.

when we merge two files this command works good.

nawk 'FNR==NR{a[FNR]=$0;next}{print a[FNR],$0}' OFS='~' file1 file2 > file3

But we try to merge multipe files (say 4 files) the above command is not working.

kindly help...

... 'cause it's not supposed to?

nawk -v OFS='~' '
  FILENAME != ARGV[ARGC-1] {a[FNR]=(FNR in a)?a[FNR] OFS $0:$0;next}
  { print a[FNR],$0}' file1 file2 fileN > fileZ
1 Like

amazing... works fine. thanks