Question

the output of my command is:

scan: DVD has 6 title(s)
...some text...
+ title 1:
...some text...
  + duration: 00:43:12
...some text...
+ title 2:
...some text...
  + duration: 00:43:12
...some text...
+ title 3:
...some text...
  + duration: 00:41:15

i want to have var for:

6 from scan: DVD has 6 title(s)

1 from + title 1:

00:43:12 from + duration: 00:43:12

not that the two last one are linked, maybe use an array For title and duration title[1]="00:43:12"

actually i'm only able to extract one information at a time but i don't want to run the command multiple time if possible. for example:

[command] |& grep -Po '(?<=DVD has )([0-9]+)')

maybe i should store the command output to a file first? what is the best way to start please ?

Était-ce utile?

La solution

You didn't specify what you wanted to do with the values, but here's an awk script that gathers them and outputs them for every line of input:

yourcommand | awk '
  NR==1{ titlecount=$4; }
  /\+ title/{ curtitle=$3; }
  /\+ duration/{ dur=$3; }
  1{ print titlecount, curtitle, dur; }
'

Autres conseils

sorry my question is not clear. Based on your answer

cat DVDscan.txt | awk '
  /+ title/{gsub(":","",$3); print $3 }
  /+ duration:/{ print $3 }'

Output:

1
00:43:12
2
00:43:12
3
00:41:15
4
00:41:15
5
00:41:17
6
00:41:17
7
00:41:15
8
00:41:15

want to store the output to multiples array:

title[1]="00:43:12"

so i will know the total number of title and can access duration for specified title.

Thanks for your time and help.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top