Code: Select all
key1
value1
key2
value2
key3
value3
...
Code: Select all
key1 value1
key2 value2
key3 value3
...Secondly, is there a way to do something like:
Code: Select all
sed 's/....\n..../.....foo..../g'Code: Select all
key1
value1
key2
value2
key3
value3
...
Code: Select all
key1 value1
key2 value2
key3 value3
...Code: Select all
sed 's/....\n..../.....foo..../g'I can easily match either a particular key or a value, but how can I match both at once in order to output them on the same line?karnesky wrote:If the key and value are differentiated in some way, just improve your matching expression.
So...If they aren't, but they are always on every other line, make a shell script which loops over every line & has different behavior for odd and even lines.
Code: Select all
#!/bin/bash
declare lastline
declare count=1;
while read line; do
if [ $(($count % 2)) = 0 ]; then
echo -e "$lastline\t$line"
fi
let $((count++));
lastline="${line}";
done < $@Code: Select all
while read line1
do
read line2
printf '%s\t%s\n' "$line1" "$line2"
doneCode: Select all
sed 'N;s/\n/\t/'ansient wrote:Secondly, is there a way to do something like:And have it operate on the entire stream instead of line-by-line?Code: Select all
sed 's/....\n..../.....foo..../g'
Code: Select all
sed -e '
:start
# after the last line is read in, go to the part where you can modify your text
$bmodify
# otherwise, read in the next line
N
# and go back (until the whole file is read)
bstart
# here, the whole file is in memory
:modify
# so you can search/replace things like this
s/A\nB/replaced/g
'