How would I join two lines using awk or sed?
for e.g.:
I have data that looks like this:
abcd
joinabcd
efgh
joinefgh
ijkl
j
They say imitation is the sincerest form of flattery.
Here's a Perl solution inspired by Dimitre's awk code:
perl -lne 'print "$_$p" if $. % 2 == 0; $p = $_' infile
$_
is the current line
$.
is the line number
You can use printf with a ternary:
awk '{printf (NR%2==0) ? $0 "\n" : $0}'
This is the answer to the question "How to make the count and the file appear on the same line" in the command:
find . -type f -exec fgrep -ci "MySQL" {} \; -print
Bryon Nicolson's answer produced the best result.
Some improvement to the "sed" script above that will take the following:
1008
-2734406.132904
2846
-2734414.838455
4636
-2734413.594009
6456
-2734417.316269
8276
-2734414.779617
and make it :
1008 -2734406.132904
2846 -2734414.838455
4636 -2734413.594009
6456 -2734417.316269
8276 -2734414.779617
the "sed" is : "sed 'h;s/.*//;G;N;s/\n/ /g'"
awk 'BEGIN{i=1}{line[i++]=$0}END{j=1; while (j<i) {print line[j+1] line[j]; j+=2}}' yourfile
No need for sed.
awk '!(NR%2){print$0p}{p=$0}' infile