On Thu, 3 Jun 2010, Scotty Logan wrote:
> On Jun 2, 2010, at 7:23 PM, Eben King wrote:
>> I'm pretty good at regexes, but programming in sed is where I break down. How does one convert this:
>>
>> A1
>> B1
>> A2
>> B2
>> A3
>> B3
>> ...
>>
>> into this:
>>
>> A1 B1
>> A2 B2
>> A3 B3
>> ...
>
>
> Assuming the data's exactly like the example:
>
> % awk '/^A/{s=$1;}/^B/{print s,$1}' data-file
What I'm trying to do is this: I have an almost-one-liner that takes a bunch 
of video files (wmv or flv mostly, the odd avi or mov or mkv or asx too), 
feeds them to "mplayer -vo null -nosound -msglevel all=4 -frames 1" which 
processes the file and prints out a bunch of stuff including a line like
VIDEO:  [WMV3]  384x288  24bpp  1000.000 fps  396.8 kbps (48.4 kbyte/s)
prints the name, then parses the lot to extract the kbps info and filename. 
The script then reassembles the stream as above, so kbps and the associated 
filename are on the same line.  Only problem is for some files mplayer 
DOESN'T print that line, so I end up with
name
kbps name
kbps name
...
Not sure how to fix that without looping grep on every file's output. 
Maybe I can use a sed or awk program that checks for two consecutive 
filenames and discards the first?
Here's the script:
#! /bin/sh
for item in "$@" ; do
  if [ -f "$item" ] ; then
   mplayer -vo null -nosound -msglevel all=4 -frames 1 "$item" 2>&1
   echo "VIDEO ( $item )"
  fi
done | grep VIDEO | cut -f 2 -d '(' | cut -f 1 -d ')' | sed -e 's/^ *//' -e 's/\([^ ]*\) .*$/\1/' -e '$!N;s/\n/ /'
-- -eben QebWenE01R@vTerYizUonI.nOetP http://royalty.mine.nu:81 SAGITTARIUS: All your friends are laughing behind your back... kill them. Take down all those naked pictures of Ernest Borgnine you've got hanging in your den. -- Weird Al, _Your Horoscope for Today_ ----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.
This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 15:46:05 EDT