A simple combination of Highlight text in code listing while also keeping syntax highlighting and Mindmap tikzpicture in beamer (reveal step by step) with one counter makes miracles (I should really thank Daniel :)).
The code:
\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{listings}
\usetheme{CambridgeUS}
% Daniel's code:
% https://tex.stackexchange.com/questions/55806/tikzpicture-in-beamer/55827#55827
\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}
% Daniel's code:
% https://tex.stackexchange.com/questions/15237/highlight-text-in-code-listing-while-also-keeping-syntax-highlighting/49309#49309
\newcounter{step}
\makeatletter
\newenvironment{btHighlight}[1][]
{\begingroup\tikzset{bt@Highlight@par/.style={#1}}\begin{lrbox}{@tempboxa}}
{\end{lrbox}\bt@HL@box[bt@Highlight@par]{@tempboxa}\endgroup}
\newcommand\btHL[1][]{%
\begin{btHighlight}[#1]\bgroup\aftergroup\bt@HL@endenv%
}
\def\bt@HL@endenv{%
\end{btHighlight}%
\egroup
}
\newcommand{\bt@HL@box}[2][]{%
\tikz[#1]{%
\pgfpathrectangle{\pgfpoint{0pt}{0pt}}{\pgfpoint{\wd #2}{\ht #2}}%
\pgfusepath{use as bounding box}%
\refstepcounter{step}
\node[visible on=<\thestep->,anchor=base west,rounded corners, fill=none,outer sep=0pt,inner xsep=0.5pt, inner ysep=2pt, #1]{\usebox{#2}};
}%
}
\makeatother
\lstset{language=sh,
basicstyle=\footnotesize\ttfamily,
keywordstyle=\footnotesize\color{blue}\ttfamily,
moredelim=**[is][\btHL]{|}{|},
}
\begin{document}
\begin{frame}[fragile]{Code}
\begin{columns}
\begin{column}{0.45\textwidth}
\setcounter{step}{0}
\begin{lstlisting}
|code 1|
|code 2|
|code 3|
\end{lstlisting}
\end{column}
\begin{column}{0.45\textwidth}
\setcounter{step}{0}
\begin{lstlisting}
|output 1|
|output 2|
|output 3|
\end{lstlisting}
\end{column}
\end{columns}
\end{frame}
\end{document}
The result:

The style visible on is in charge of making visible the code: the sequence is achieved by means of the counter step, incremented at each step the code is highlighted. To make code and output synchronized, one just has to reset the counter before opening the lstlisting environment.
Disclaimer
I used the columns environment because in this case looks better, but the solution works also without it.
Improved solution: overlaying blocks of code and opacity customizable
To display a block of lines, things are a bit more complicated: we need another environment in which the counter is not increased. So we end up with two types of delimiters: the first one which let the counter increase (you should use it for the first line of the block) and the second type keeps the previous value such that the current line is displayed in the same overlay of the first line of the block (use this for all other lines of code).
In order to customize the opacity of the lines, a specific key has been introduced:
\pgfkeys{/tikz/.cd,
set opacity/.initial=0,
set opacity/.get=\opacity,
set opacity/.store in=\opacity,
}
applied to:
\tikzset{
invisible/.style={opacity=\opacity},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}
Initially, the opacity is set to 0 thus the code appears magically: in the example it is shown how to modify it in order to get some semi transparent effect.
The code:
\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{listings}
\usetheme{CambridgeUS}
% key to customize the opacity
\pgfkeys{/tikz/.cd,
set opacity/.initial=0,
set opacity/.get=\opacity,
set opacity/.store in=\opacity,
}
% Daniel's code:
% https://tex.stackexchange.com/questions/55806/tikzpicture-in-beamer/55827#55827
\tikzset{
invisible/.style={opacity=\opacity},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}
% Daniel's code:
% https://tex.stackexchange.com/questions/15237/highlight-text-in-code-listing-while-also-keeping-syntax-highlighting/49309#49309
\newcounter{step}
\makeatletter
\newenvironment{btHighlight}[1][]
{\begingroup\tikzset{bt@Highlight@par/.style={#1}}\begin{lrbox}{@tempboxa}}
{\end{lrbox}\bt@HL@box[bt@Highlight@par]{@tempboxa}\endgroup}
\newcommand\btHL[1][]{%
\begin{btHighlight}[#1]\bgroup\aftergroup\bt@HL@endenv%
}
\def\bt@HL@endenv{%
\end{btHighlight}%
\egroup
}
\newcommand{\bt@HL@box}[2][]{%
\tikz[#1]{%
\pgfpathrectangle{\pgfpoint{0pt}{0pt}}{\pgfpoint{\wd #2}{\ht #2}}%
\pgfusepath{use as bounding box}%
\refstepcounter{step}
\node[visible on=<\thestep->,anchor=base west,rounded corners, fill=none,outer sep=0pt,inner xsep=0.5pt, inner ysep=2pt, #1]{\usebox{#2}};
}%
}
\newenvironment{btHighlights}[1][]
{\begingroup\tikzset{bt@Highlights@par/.style={#1}}\begin{lrbox}{@tempboxa}}
{\end{lrbox}\bt@HLs@box[bt@Highlights@par]{@tempboxa}\endgroup}
\newcommand\btHLs[1][]{%
\begin{btHighlights}[#1]\bgroup\aftergroup\bt@HLs@endenv%
}
\def\bt@HLs@endenv{%
\end{btHighlights}%
\egroup
}
\newcommand{\bt@HLs@box}[2][]{%
\tikz[#1]{%
\pgfpathrectangle{\pgfpoint{0pt}{0pt}}{\pgfpoint{\wd #2}{\ht #2}}%
\pgfusepath{use as bounding box}%
\node[visible on=<\thestep->,anchor=base west,rounded corners, fill=none,outer sep=0pt,inner xsep=0.5pt, inner ysep=2pt, #1]{\usebox{#2}};
}%
}
\makeatother
\lstset{language=sh,
basicstyle=\footnotesize\ttfamily,
keywordstyle=\footnotesize\color{blue}\ttfamily,
moredelim=[is][\btHL]{|}{|}, % counter increased
moredelim=[is][\btHLs]{}{}, % counter not increased
}
\begin{document}
\begin{frame}[fragile]{Code}
\begin{columns}
\begin{column}{0.45\textwidth}
\setcounter{step}{0}
\begin{lstlisting}
|code 1 line 1|
code 1 line 2
code 1 line 3
|code 2 line 1|
code 2 line 2
|code 3 line 1|
code 3 line 2
code 3 line 3
code 3 line 4
\end{lstlisting}
\end{column}
\begin{column}{0.45\textwidth}
\setcounter{step}{0}
\tikzset{set opacity=0.2}
\begin{lstlisting}
|output 1|
|output 2|
|output 3|
\end{lstlisting}
\end{column}
\end{columns}
\end{frame}
\end{document}
The result:
