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
PikK45
January 17, 2013, 9:29am
4
It does work fine for me!
1 Like
PikK45
January 17, 2013, 9:53am
6
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
mohammedsadath:
Attached screenshot.
What operating system are you using?
1 Like
Oracle Corporation-SunOS 5.10
(this is what is displayed when i log into UNIX)
Yoda
January 17, 2013, 11:07am
9
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...
thanks bipinajith and everyone...
---------- 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