0

I have .srt files that consist out of paragraphs with the same pattern. the amount of paragraphs in each document is different. I wanna keep the number of the paragraph, keep the time in the second line, and then basically only keep the "BAROMETER:" and the number next to that. the last line can also go out.

Every help is much appreciated!

I am running a mac and would like to do it in automator or any other program that

this is how the paragraphs look like now

1
00:00:01,000 --> 00:00:02,000
HOME(11.6488,51.7185) 2016.06.02 13:19:11
GPS(11.6488,51.7185,18) BAROMETER:3.5
ISO:100 Shutter:400 A:63 AA:63 EV: Fnum:6.3 

2
00:00:02,000 --> 00:00:03,000
HOME(11.6488,51.7185) 2016.06.02 13:19:12
GPS(11.6488,51.7185,17) BAROMETER:3.5
ISO:100 Shutter:400 A:63 AA:63 EV: Fnum:6.3 

and this is how i would like them to look like afterwards

3
00:00:03,000 --> 00:00:04,000
BAROMETER:4.3

4
00:00:04,000 --> 00:00:05,000
BAROMETER:5.3
Rishav
  • 3,818
  • 1
  • 31
  • 49
Philipp
  • 23
  • 4

1 Answers1

1
grep -oE "^[0-9].*$|^$|BAROMETER.*$" input-file


EDIT: Based on your comment it seems that you want to do it for every file in a folder and replace in-place. In this case it is better to use find and sed, e.g.
find "$@" -type f -name "*.srt" -exec \
    sed -i.bak '/^[0-9]\|BAROMETER\|^$/!d;s/^.*\(BAROMETER\)/\1/' {} \;

I have never used Automator for anything really, but there is quite detailed examples in the documentation.

jil
  • 2,601
  • 12
  • 14
  • I tried hard but could not get a complete automator action out of it. Let's say I wanna do this action to all files in a folder that I choose I would 1. create a new Application in automator 2. add "check folder" 3. add a shell script the rest I can not really figure out myself :( basically my dream would be an app asking for a folder, converting all the text files in the folder and saving them with the same names to a location that i can choose. thanks a lot in advance, your help is mich appreciated! – Philipp Jun 13 '16 at 16:03
  • Apparently, the regular expression used by sed is not what I need. It removes ALL contents of my original .srt file... Can someone help me replace the regular expression with a better version? Please find an example .srt file attached [link](https://dl.dropboxusercontent.com/u/1937633/DJI_0002.SRT) – Philipp Oct 12 '16 at 18:18