[opensuse] bash -- Where in the heck are "^M...80 spaces...^M" getting written by tee?? (can I catch it?)
Guys, This is baffling... another rankinism... I get that this is a carriage return in the file and it is usually associated with dos/unix editing of files, but I can't tell if I'm causing it or if it is just dvgrab. If I output sdtout/stderr to a terminal all looks good, but when I check the log file, I have two spaces between every line. Here is the console output: Found AV/C device with GUID 0x08004601017ede99 Waiting for DV... Capture Started "dcrv-1999.05.08_09-37-33.dv": 467.72 MiB 4087 frames timecode 00:02:16.13 date 1999.05.08 09:41:49 "dcrv-1999.05.08_16-23-57.dv": 784.15 MiB 6852 frames timecode 00:06:05.03 date 1999.05.08 16:37:40 "dcrv-1999.05.08_19-03-13.dv": 718.69 MiB 6280 frames timecode 00:09:34.19 date 1999.05.08 19:06:42 Here is the log: Found AV/C device with GUID 0x08004601017ede99 Waiting for DV... Capture Started "dcrv-1999.05.08_09-37-33.dv": 467.72 MiB 4087 frames timecode 00:02:16.13 date 1999.05.08 09:41:49 ^M ^M"dcrv-1999.05.08_16-23-57.dv": 784.15 MiB 6852 frames timecode 00:06:05.03 date 1999.05.08 16:37:40 ^M ^M"dcrv-1999.05.08_19-03-13.dv": 718.69 MiB 6280 frames timecode 00:09:34.19 date 1999.05.08 19:06:42 Literally, every line output from dvgrab has an extra: '^M.....80spaces.....^M' It's easy enough to kill in vi with '%s/^v^m//g' and '%s/^ *//', but I want to figure out what is causing this garbage. The script I'm using is straight forward. 2 temporary files are written to get the information in the order I want it, and the information is then appended to a log file and a tape index: <snip> # initialize vars and files tmpfn=/tmp/dvtmp.log tmpapp=/tmp/dvapp.log :>$tmpfn :>$tmpapp # write stuff echo -e "\nTape: $tapect -- \n" >> $tmpapp echo -e "\nCapture Started: $(date '+%b %e %T')\n" | tee -a $tmpfn # this is the command that is giving me garbage dvgrab -rewind -timestamp -autosplit=3600 -format raw dcrv- 2>&1 | tee -a $tmpfn dvcont rewind # append capture log cat $tmpfn >> /dat_e/dv/capture.log # get list and append dvgrab log to bottom ls -l >> $tmpapp cat $tmpfn >> $tmpapp # add all that stuff to the tape index cat $tmpapp >>/dat_e/dv/tape-idx.txt I can't see where I'm causing the carriage returns and 80 spaces to get appended to the dvgrab output... It could be me, but I can't see it! Anybody else see anything wrong with the tee call or anything else that could be causing it? Other than me doing something dumb, it looks like it is just dvgrab spitting out 'a carriage return + 80 spaces + another carriage return' with every dv clip it processes... If it is dvgrab, then is there a way I can have bash strip this info before it gets written to the files? The terminal does it by default evidently, because the output I get from stdout/stderr looks correct in konsole, so can I pipe the output through something (hopefully lighter than sed) that would strip it before I pipe it to tee? -- David C. Rankin, J.D.,P.E. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Wed, 28 Sep 2011, David C. Rankin wrote:
This is baffling... another rankinism...
Nah. Just some standard stuff. [..]
Here is the log:
Found AV/C device with GUID 0x08004601017ede99 Waiting for DV... Capture Started "dcrv-1999.05.08_09-37-33.dv": 467.72 MiB 4087 frames timecode 00:02:16.13 date 1999.05.08 09:41:49 ^M ^M"dcrv-1999.05.08_16-23-57.dv": 784.15 MiB 6852 frames timecode 00:06:05.03 date 1999.05.08 16:37:40 ^M ^M"dcrv-1999.05.08_19-03-13.dv": 718.69 MiB 6280 frames timecode 00:09:34.19 date 1999.05.08 19:06:42
Literally, every line output from dvgrab has an extra:
'^M.....80spaces.....^M' [..] If it is dvgrab, then is there a way I can have bash strip this info before it gets written to the files? The terminal does it by default evidently, because the output I get from stdout/stderr looks correct in konsole, so can I pipe the output through something (hopefully lighter than sed) that would strip it before I pipe it to tee?
It IS dvgrab, counting on logging to a terminal. Other programs do the right thing[tm] and switch behaviour accordingly. Consider this: $ for i in $(seq 1 100); do printf "\r%3i%%" $i; sleep 0.1; done; printf "\n"; Looks fine in your terminal, eh? Now, log that (I have a /dh/ in the ramdisk /dev/shm ;) $ { for i in $(seq 1 100); do printf "\r%3i%%" $i; sleep 0.1; done; printf "\n"; } > /dev/shm/dh/process.log 2>&1 ==== $ od -tx1z /dev/shm/dh/process.log ==== 0000000 0d 20 20 31 25 0d 20 20 32 25 0d 20 20 33 25 0d >. 1%. 2%. 3%.< 0000020 20 20 34 25 0d 20 20 35 25 0d 20 20 36 25 0d 20 > 4%. 5%. 6%. < 0000040 20 37 25 0d 20 20 38 25 0d 20 20 39 25 0d 20 31 > 7%. 8%. 9%. 1< 0000060 30 25 0d 20 31 31 25 0d 20 31 32 25 0d 20 31 33 >0%. 11%. 12%. 13< ==== ^^ ^^ ^^ == \r == ^M And so, no, the terminal doesn't strip anything, but it _interprets_ the \r and consequently erases the line (as in my example). For more advanced terminal stuff see 'man console_codes' ;) So, yes, you need to strip the stuff with sed, as neither grep nor cut would help, I think. But don't worry about "light", one sed suffices and once started ... For my example { ... } 2>&1 | tee /dev/stderr | sed 's/.*\r//' > log works nicely (it leaves the 100% in the log, as is probably wanted). For dvgrab, try e.g. to be more specific such as { ... } 2>&1 | tee /dev/stderr | sed 's/^[[:space:]]*\r//' > log HTH, -dnh -- Apple's original usability studies contradicted the Xerox ones. The difference? Xerox studied people who were used to the idea of computers and user interfaces. Apple studied random lusers." -- Peter da Silva -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David C. Rankin said the following on 09/28/2011 07:09 PM:
# write stuff echo -e "\nTape: $tapect -- \n">> $tmpapp echo -e "\nCapture Started: $(date '+%b %e %T')\n" | tee -a $tmpfn
Are you sure that you don't mean echo -n -e "\nTape: $tapect -- \n">> $tmpapp echo -n -e "\nCapture Started: $(date '+%b %e %T')\n" | tee -a $tmpfn And you do realise that what you see on the screen and what goes into the file in the second case are two different things. As for the 80 spaces ... Dunno. -- If you are using Windows 2000, there is no chance that DES is your weak link. The only justification for using 3DES is that it is cheap. -- William Hugh Murray, CISSP -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello Anton, David[1], On Wed, 28 Sep 2011, Anton Aylward wrote:
David C. Rankin said the following on 09/28/2011 07:09 PM:
# write stuff echo -e "\nTape: $tapect -- \n">> $tmpapp echo -e "\nCapture Started: $(date '+%b %e %T')\n" | tee -a $tmpfn
Are you sure that you don't mean
echo -n -e "\nTape: $tapect -- \n">> $tmpapp echo -n -e "\nCapture Started: $(date '+%b %e %T')\n" | tee -a $tmpfn
And you do realise that what you see on the screen and what goes into the file in the second case are two different things.
Actually, he probably wants to use: printf "Tape: %s -- \n" "$tapect" >> $tmpapp date '+Capture Started: %b %e %T' | tee -a $tmpfn Remember: strftime/date take arbitrary strings with embedded %-escapes (though current 'date' seems to add an implicit '\n' at the end, I don't remember that from strftime and maybe older 'date' versions (or were those gobbled-by-$() '\n'?)) [those '\n' at the beginning seem dubious, add them if actually wanted] Oh, and BTW: if you do a lot of redirecting stdout/stderr stuff to a logfile: reroute stdout/stderr via exec at the start of the script. See: man -P 'less +"/^REDIR"' bash e.g. do a exec &>>$tmpapp or a exec 1>>foo.log exec 2>>foo.err at the start of the script. Also see 'man logger', e.g. foo | logger -s -t foo Use '{ ... } | logger -s -t foo' for logging multiple commands.
As for the 80 spaces ... Dunno.
See my first mail ;) HTH, -dnh [1] yikes, that always looks so self-referential ;) -- just had a great phone call from a user Her : How is it you always maintain a sense of humour? Me : Because I'm completely insane. Her : ...yyyyyes. Yes, that would explain it. Bye! -- Jim -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 09/29/2011 03:13 AM, David Haller wrote:
Actually, he probably wants to use:
printf "Tape: %s -- \n" "$tapect">> $tmpapp date '+Capture Started: %b %e %T' | tee -a $tmpfn
:) Lazy really! I just haven't gotten around to adding the parse that grabs the beginning date and ending date from the filenames output by dvgrab... I've written the parse, just haven't plugged it into the script yet :) What I do with the script is just output "Tape: # -- " and then come back and just confirm the log and add mm/dd/yyyy - mm/dd/yyyy the old way (with the keyboard :) What I was going to do is take the dvtmp.log containing (e.g.): "dcrv-2003.07.27_18-26-46.dv fr-MiB tc-timecode d-date t-2003.07.27 18:28:12 <snip> "dcrv-2003.09.12_16-30-27.dv fr-MiB tc-timecode d-date t-2011.09.28 15:58:48 and grab the date from the filename part of the string (can't use the date at end of line..) That's in the todo pile, but for now, fingers work :) Thank you David and Anton for your help. -- David C. Rankin, J.D.,P.E. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 09/29/2011 12:40 PM, David C. Rankin wrote: <snip>
What I do with the script is just output "Tape: # -- " and then come back and just confirm the log and add mm/dd/yyyy - mm/dd/yyyy the old way (with the keyboard :)
What I was going to do is take the dvtmp.log containing (e.g.):
"dcrv-2003.07.27_18-26-46.dv fr-MiB tc-timecode d-date t-2003.07.27 18:28:12 <snip> "dcrv-2003.09.12_16-30-27.dv fr-MiB tc-timecode d-date t-2011.09.28 15:58:48
and grab the date from the filename part of the string (can't use the date at end of line..) That's in the todo pile, but for now, fingers work :)
Thank you David and Anton for your help.
Here is what I came up with to get the dates: ## parse dates OLDIFS=$IFS IFS=$'\n' clipct=1 for i in $(grep \"d dvtmp.log); do dt=${i//\"dcrv-} dt=${dt//_*} [[ $clipct -eq 1 ]] && first_dt=$dt ((clipct++)) done last_dt=$dt IFS=$OLDIFS echo -e "\n first_dt: $first_dt\n last_dt: $last_dt\n" dnh, all see any holes in it or a way to make it better? I was just going to throw it an a function and write it out... -- David C. Rankin, J.D.,P.E. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 09/29/2011 01:40 PM, David C. Rankin wrote:
dnh, all see any holes in it or a way to make it better? I was just going to throw it an a function and write it out...
Just FYI, here is what I ended up with. I added an intermediate tmp file to strip the \r: #!/bin/bash ## dir test [[ -d /dat_e/dv/new ]] || { echo "No /dat_e/dv/new, exiting..."; exit 2; } cd /dat_e/dv/new || { echo "cannot change into /dat_e/dv/new, exiting..."; exit 2; } ## read tape count and set up vars & tmp files tapect=${1:-$(</dat_e/dv/tapect.txt)} tmpfn=/tmp/dvtmp.log tmpapp=/tmp/dvapp.log :>$tmpfn :>$tmpapp first_dt="" last_dt="" ## fix date format from yyyy.mm.dd to mm/dd/yyyy fixdfmt() { [[ -n $1 ]] || { echo "ERROR: Nothing passed to function 'fixdfmt'"; return 1; } year=${1//.*} day=${1##*.} mo=${1%.*} mo=${mo##*.} echo "${mo}/${day}/${year}" return 0 } ## parse dates from $tmpfn to get start and end dates for tape index getdates() { OLDIFS=$IFS IFS=$'\n' clipct=1 for i in $(grep \"d $tmpfn); do dt=${i//\"dcrv-} dt=${dt//_*} [[ $clipct -eq 1 ]] && first_dt=$(fixdfmt $dt) ((clipct++)) done last_dt=$(fixdfmt $dt) IFS=$OLDIFS } ## download video with output to tmpfn & rewind tape when done echo -e "\nCapture Started: $(date '+%b %e %T')\n" | tee -a $tmpfn dvgrab -rewind -timestamp -autosplit=3600 -format raw dcrv- 2>&1 | tee -a $tmpfn dvcont rewind ## fix the \r issue cat $tmpfn | sed 's/^[[:space:]]*\r//' > /tmp/fix.log cp /tmp/fix.log $tmpfn ## get tape begin and end dates getdates ## write tape No. and begin & end dates to append file echo -e "\nTape: $tapect -- $first_dt - $last_dt\n" >> $tmpapp ## write dir content and capture info to append file and append to tape index, update capture log ls -l >> $tmpapp cat $tmpfn >> $tmpapp cat $tmpapp >>/dat_e/dv/tape-idx.txt cat $tmpfn >> /dat_e/dv/capture.log ## move dv clips to permanent dir and mirror on /dat_f mv /dat_e/dv/new/* /dat_e/dv/sony cp -uav /dat_e/dv/{sony,tape-idx.txt} /dat_f/dv/ ## update tape counter tapenext=$tapect ((tapenext+=1)) echo $tapenext >/dat_e/dv/tapect.txt echo " Tape count updated to: $tapenext" exit 0 -- David C. Rankin, J.D.,P.E. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Thu, 29 Sep 2011, David C. Rankin wrote:
On 09/29/2011 01:40 PM, David C. Rankin wrote:
dnh, all see any holes in it or a way to make it better? I was just going to throw it an a function and write it out...
Just FYI, here is what I ended up with. I added an intermediate tmp file to strip the \r:
#!/bin/bash
## dir test [[ -d /dat_e/dv/new ]] || { echo "No /dat_e/dv/new, exiting..."; exit 2; }
I prefer to use the simple test -d /dat_e/dv/new || { echo "No /dat_e/dv/new, exiting..."; exit 2; }
cd /dat_e/dv/new || { echo "cannot change into /dat_e/dv/new, exiting..."; exit 2; }
You could simply change to the dir, you'll get a fitting message: $ cd /dat_e/dv/new bash: cd: /dat_e/dv/new: No such file or directory i.e. just use cd /dat_e/dv/new || exit 2 instead of above two tests.
## read tape count and set up vars & tmp files tapect=${1:-$(</dat_e/dv/tapect.txt)} tmpfn=/tmp/dvtmp.log tmpapp=/tmp/dvapp.log :>$tmpfn :>$tmpapp first_dt="" last_dt=""
## fix date format from yyyy.mm.dd to mm/dd/yyyy fixdfmt() { [[ -n $1 ]] || { echo "ERROR: Nothing passed to function 'fixdfmt'"; return 1; } year=${1//.*} day=${1##*.} mo=${1%.*} mo=${mo##*.} echo "${mo}/${day}/${year}" return 0 }
An fun alternative I came up with: fixdfmt() { test -z "$1" && { echo "ERROR: Nothing passed to function 'fixdfmt'" >&2; return 1; } _fixdfmt() { echo "$3/$2/$1"; } oIFS="$IFS"; IFS="." _fixdfmt $1 IFS="$oIFS" # unset _fixedfmt }
## parse dates from $tmpfn to get start and end dates for tape index getdates() { OLDIFS=$IFS IFS=$'\n' clipct=1 for i in $(grep \"d $tmpfn); do dt=${i//\"dcrv-} dt=${dt//_*} [[ $clipct -eq 1 ]] && first_dt=$(fixdfmt $dt) ((clipct++)) done last_dt=$(fixdfmt $dt) IFS=$OLDIFS }
## download video with output to tmpfn & rewind tape when done echo -e "\nCapture Started: $(date '+%b %e %T')\n" | tee -a $tmpfn
date '+\nCapture Started: %b %e %T\n' | tee -a $tmpfn
dvgrab -rewind -timestamp -autosplit=3600 -format raw dcrv- 2>&1 | tee -a $tmpfn dvcont rewind
## fix the \r issue cat $tmpfn | sed 's/^[[:space:]]*\r//' > /tmp/fix.log cp /tmp/fix.log $tmpfn
You could combine that with the grep. Do you get those \r on the same lines as the '"dcrv-'? Alternatively: sed -i 's/^[[:space:]]*\r//' $tmpfn HTH, -dnh -- If you don't see why, please stay the fuck away from my code. -- Paul "Rusty" Russel, in /usr/src/linux/Documentation/DocBook/kernel-locking.tmpl -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 09/30/2011 07:58 AM, David Haller wrote:
## dir test
[[ -d /dat_e/dv/new ]] || { echo "No /dat_e/dv/new, exiting..."; exit 2; } I prefer to use the simple
test -d /dat_e/dv/new || { echo "No /dat_e/dv/new, exiting..."; exit 2; }
<snip> I have see this the 'test <condition>' verses [[ <condition> ]] verses [ <condition> ] arguments a number of times and don't understand enough about the differences. I know the [[ <condition> ]] was an 'improvement' over the [ <condition> ] notation, but other than the flexibility test offers in testing for 'command' return success or failure rather than conditional <conditions> (eg. ==, -eq, etc...) I don't know where the primary concern lies. Posix compatibility?? Some 'tricks' still require the old [ <condition> ] or 'test' constructs and will not work with [[ <condition> ]]. For example the integer test: if [ $var -eq $var ] >/dev/null; then printf "\$var -- is an integer" else printf "\$var -- is NOT an integer" fi if test $var -eq $var >/dev/null; then printf "\$var -- is an integer" else printf "\$var -- is NOT an integer" fi Dunno why, but I know it is so :)
## read tape count and set up vars& tmp files tapect=${1:-$(</dat_e/dv/tapect.txt)} tmpfn=/tmp/dvtmp.log tmpapp=/tmp/dvapp.log :>$tmpfn :>$tmpapp first_dt="" last_dt=""
## fix date format from yyyy.mm.dd to mm/dd/yyyy fixdfmt() { [[ -n $1 ]] || { echo "ERROR: Nothing passed to function 'fixdfmt'"; return 1; } year=${1//.*} day=${1##*.} mo=${1%.*} mo=${mo##*.} echo "${mo}/${day}/${year}" return 0 } An fun alternative I came up with:
fixdfmt() { test -z "$1"&& { echo "ERROR: Nothing passed to function 'fixdfmt'">&2; return 1; } _fixdfmt() { echo "$3/$2/$1"; } oIFS="$IFS"; IFS="." _fixdfmt $1 IFS="$oIFS" # unset _fixedfmt }
Clearly shows the relative experience levels among authors - poetry verses a simple paragraph. Using IFS for it's intended purpose is clearly illustrated instead of using it as a hammer :)
## parse dates from $tmpfn to get start and end dates for tape index getdates() { OLDIFS=$IFS IFS=$'\n' clipct=1 for i in $(grep \"d $tmpfn); do dt=${i//\"dcrv-} dt=${dt//_*} [[ $clipct -eq 1 ]]&& first_dt=$(fixdfmt $dt) ((clipct++)) done last_dt=$(fixdfmt $dt) IFS=$OLDIFS }
## download video with output to tmpfn& rewind tape when done echo -e "\nCapture Started: $(date '+%b %e %T')\n" | tee -a $tmpfn date '+\nCapture Started: %b %e %T\n' | tee -a $tmpfn
Damn, I knew I would have to look something up in 'man bash' in the course of this discussion :)
dvgrab -rewind -timestamp -autosplit=3600 -format raw dcrv- 2>&1 | tee -a $tmpfn dvcont rewind
## fix the \r issue cat $tmpfn | sed 's/^[[:space:]]*\r//'> /tmp/fix.log cp /tmp/fix.log $tmpfn You could combine that with the grep. Do you get those \r on the same lines as the '"dcrv-'?
Alternatively:
sed -i 's/^[[:space:]]*\r//' $tmpfn
Err... umm..., I think so?? 00000060 2e 2e 2e 0a 43 61 70 74 75 72 65 20 53 74 61 72 |....Capture Star| 00000070 74 65 64 0a 22 64 63 72 76 2d 32 30 30 33 2e 30 |ted."dcrv-2003.0| 00000080 37 2e 32 37 5f 31 38 2d 30 35 2d 35 34 2e 64 76 |7.27_18-05-54.dv| 00000090 22 3a 20 20 20 39 39 39 2e 39 38 20 4d 69 42 20 |": 999.98 MiB | 000000a0 20 38 37 33 38 20 66 72 61 6d 65 73 20 74 69 6d | 8738 frames tim| 000000b0 65 63 6f 64 65 20 30 30 3a 30 34 3a 35 31 2e 31 |ecode 00:04:51.1| 000000c0 38 20 64 61 74 65 20 32 30 30 33 2e 30 37 2e 32 |8 date 2003.07.2| 000000d0 37 20 31 38 3a 32 36 3a 34 36 0a 0d 20 20 20 20 |7 18:26:46.. | 000000e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 00000120 20 20 20 20 20 20 20 20 20 20 20 20 0d 22 64 63 | ."dc| 00000130 72 76 2d 32 30 30 33 2e 30 37 2e 32 37 5f 31 38 |rv-2003.07.27_18| 00000140 2d 32 36 2d 34 36 2e 64 76 22 3a 20 20 20 32 39 |-26-46.dv": 29| 00000150 34 2e 30 30 20 4d 69 42 20 20 32 35 36 39 20 66 |4.00 MiB 2569 f| 00000160 72 61 6d 65 73 20 74 69 6d 65 63 6f 64 65 20 30 |rames timecode 0| 00000170 30 3a 30 36 3a 31 37 2e 31 31 20 64 61 74 65 20 |0:06:17.11 date | 00000180 32 30 30 33 2e 30 37 2e 32 37 20 31 38 3a 32 38 |2003.07.27 18:28| 00000190 3a 31 32 0a 0d 20 20 20 20 20 20 20 20 20 20 20 |:12.. | 000001a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * Actually, It looks like it is in a line by itself: 00000240 2e 31 34 20 31 38 3a 35 33 3a 35 39 0a 0d 20 20 |.14 18:53:59.. | 00000250 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 00000290 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0d 22 | ."| 000002a0 64 63 72 76 2d 32 30 30 33 2e 30 38 2e 31 36 5f |dcrv-2003.08.16_|
HTH, -dnh
It does, thanks! -- David C. Rankin, J.D.,P.E. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Sat, 01 Oct 2011, David C. Rankin wrote:
On 09/30/2011 07:58 AM, David Haller wrote:
## dir test
[[ -d /dat_e/dv/new ]] || { echo "No /dat_e/dv/new, exiting..."; exit 2; } I prefer to use the simple
test -d /dat_e/dv/new || { echo "No /dat_e/dv/new, exiting..."; exit 2; }
<snip>
I have see this the 'test <condition>' verses [[ <condition> ]] verses [ <condition> ] arguments a number of times and don't understand enough about the differences. I know the [[ <condition> ]] was an 'improvement' over the [ <condition> ] notation, but other than the flexibility test offers in testing for 'command' return success or failure rather than conditional <conditions> (eg. ==, -eq, etc...) I don't know where the primary concern lies. Posix compatibility??
Well, the test-binary / [ symlink, the shell builtin test / [ alias are quite portable (except -a/-o stuff). [[ ]] is relatively new AFAIK. Search for '\[\[' in man bash for [[ expression ]] to read up on what [[ ]] can. 'test' is much simpler (e.g. no pattern matching). For the stuff that 'test' can do (e.g. testing for existance), I prefer it and also to use 'test EXPR' instead of '[ EXPR ]', esp. because the latter needs the 'space]' sequence at the end (makes for ugly bugs if you use '[ EXPR];' by mistake, and also because it makes people think that [ ] is shell-syntax like [[ ]] or () or {}, which gets you stuff like (real world example): if [ "`ls /media/ | grep "device name"`" != "" ]; then [..]
## download video with output to tmpfn& rewind tape when done echo -e "\nCapture Started: $(date '+%b %e %T')\n" | tee -a $tmpfn date '+\nCapture Started: %b %e %T\n' | tee -a $tmpfn
Damn, I knew I would have to look something up in 'man bash' in the course of this discussion :)
In this case you'd need to look into 'man date' or rather 'info date'.
dvgrab -rewind -timestamp -autosplit=3600 -format raw dcrv- 2>&1 | tee -a $tmpfn dvcont rewind
## fix the \r issue cat $tmpfn | sed 's/^[[:space:]]*\r//'> /tmp/fix.log cp /tmp/fix.log $tmpfn You could combine that with the grep. Do you get those \r on the same lines as the '"dcrv-'?
Alternatively:
sed -i 's/^[[:space:]]*\r//' $tmpfn
Err... umm..., I think so??
00000060 2e 2e 2e 0a 43 61 70 74 75 72 65 20 53 74 61 72 |....Capture Star| 00000070 74 65 64 0a 22 64 63 72 76 2d 32 30 30 33 2e 30 |ted."dcrv-2003.0| 00000080 37 2e 32 37 5f 31 38 2d 30 35 2d 35 34 2e 64 76 |7.27_18-05-54.dv| 00000090 22 3a 20 20 20 39 39 39 2e 39 38 20 4d 69 42 20 |": 999.98 MiB | 000000a0 20 38 37 33 38 20 66 72 61 6d 65 73 20 74 69 6d | 8738 frames tim| 000000b0 65 63 6f 64 65 20 30 30 3a 30 34 3a 35 31 2e 31 |ecode 00:04:51.1| 000000c0 38 20 64 61 74 65 20 32 30 30 33 2e 30 37 2e 32 |8 date 2003.07.2| 000000d0 37 20 31 38 3a 32 36 3a 34 36 0a 0d 20 20 20 20 |7 18:26:46.. | 000000e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | * 00000120 20 20 20 20 20 20 20 20 20 20 20 20 0d 22 64 63 | ."dc| 00000130 72 76 2d 32 30 30 33 2e 30 37 2e 32 37 5f 31 38 |rv-2003.07.27_18|
That looks as if the format of the lines is: "filename" frame/time stuff\n\rspaces\r Or rather (except on the first line): \rspaces\r"filename" frame/time stuff\n So, yes, you can combine that with the grep: getdates() { OLDIFS="$IFS" IFS=$'\n' clipct=1 ### 'for..do' broken into 3 lines for this mail only for dt in $(sed -n '/"dcrv/s/^\(\r +\r\)?"dcrv-\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)_.*'/\3\/\2\/\1/p' "$tmpfn" ); do test $clipct -eq 1 && first_dt=$(fixdfmt $dt) ((clipct++)) done last_dt=$(fixdfmt $dt) IFS="$OLDIFS" } Oh, I see that you want to have $tmpfn also "as is" in the $tmpapp. Then you should just use the sed -i 's/^[[:space:]]*\r//' $tmpfn instead of cat $tmpfn | sed 's/^[[:space:]]*\r//' > /tmp/fix.log cp /tmp/fix.log $tmpfn and leave getdates as it were or use getdates() { OLDIFS="$IFS" IFS=$'\n' clipct=1 for dt in $(sed -n '/"dcrv/s/"dcrv-\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)_.*'/\3\/\2\/\1/p' "$tmpfn"); do test $clipct -eq 1 && first_dt="$dt" ((clipct++)) done last_dt="$dt" IFS="$OLDIFS" } Yes, the sed looks ugly and complicated but is actually quite simple ;) -dnh -- Q: "Excession is particularly popular because of its copious detail concerning the Ships and Minds of the Culture, its great AIs: their outrageous names, their dangerous senses of humour. Is this what gods would actually be like?" A: "If we're lucky." -- Iain M. Banks -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (3)
-
Anton Aylward
-
David C. Rankin
-
David Haller