1

Basically, using a bash script, I extracted two sets of values, which I want to gnuplot as my X and Y axis. I'd like to write to a file multiple lines, each of them containing a value of my X-axis and Y-axis for gnuplot practical purpose.

My X-axis string is like

0\n 
0.5\n
1\n
1.5\n
2\n
2.5\n

And the Y-axis string (equal line number) :

123\n 
321\n
468\n
789\n
890\n
2345\n

What I'd like to write to a file is :

0 123\n 
0.5 321\n
1 468\n
1.5 789\n
2 890\n
2.5 2345\n

Thanks in advance. Writing this to a file is just an idea and definitely not compulsory, I just want to be able to gnuplot this curve !

SOKS
  • 190
  • 3
  • 11
  • Just marked as duplicated thinking that it really is. As per having gold badge in bash, it was marked automatically. Please cross check if that other answer is helpful enough (I think so). Otherwise we can reopen the question. – fedorqui Jun 03 '14 at 09:04
  • @fedorqui Yes, that is a duplicate. Another similar question is [Get ratio from 2 files in gnuplot](http://stackoverflow.com/questions/20069641/get-ratio-from-2-files-in-gnuplot), with a python script as replacement for `paste` is this is not available. – Christoph Jun 03 '14 at 10:56

1 Answers1

0

Try this awk command,

awk -F'\' 'FNR==NR{a[FNR]=$1;next} {print a[FNR],$0}' file1 file2

Example:

$ cat file1
0\n 
0.5\n
1\n
1.5\n
2\n
2.5\n

$ cat file2

123\n 
321\n
468\n
789\n
890\n
2345\n


$ awk -F'\' 'FNR==NR{a[FNR]=$1;next} {print a[FNR],$0}' file1 file2
0 123\n 
0.5 321\n
1 468\n
1.5 789\n
2 890\n
2.5 2345\n
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274