Sponsored Content
Top Forums Shell Programming and Scripting Automating find and replace REGEX expressions in a script Post 303045344 by bedtime on Tuesday 17th of March 2020 12:33:43 PM
Old 03-17-2020
Automating find and replace REGEX expressions in a script

I've made several REGEX expressions which I would like to use to find and replace text in a .srt file:

For example, below, the first is the pattern to be found. The second is the replacement. These work with my text editor just fine:
Code:
\n\n(?=\d{1,}\n)
~~~

(?<=-->\s\d{2}\:\d{2}\:\d{2}\,\d{3})\n
```

 (?<=\d)\n(?=\d{2}\:\d{2}\:\d{2}\,\d{3} -->)
'''

There are several more that I have, so I'd like to be able to throw them into a script which would read and replace each successively and for every instance in a given file.


Any idea of a program that could do this? I've had a look at SED, but it seems that using it might require a lot of extra work in editing the expressions.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

automating file search and replace text

Hi, I am trying something like this: Let's say I have a file called File1 with contents: x=-0.3 y=2.1 z=9.0 I have another file, File2, with contents: xx= yy= zz= (nothing after "="). What I want to do is get the value of x in File1 and set it to xx in File2, i.e., xx=-0.3. And the... (3 Replies)
Discussion started by: ommatidia
3 Replies

2. Shell Programming and Scripting

A simple find and replace without using any regex (bash)

Hi, I need to do an exact find and replace (I don't want to use regular expressions because the input comes from user). I want to find a line that matches the user's input text and replace it with an empty string. For example, let's say the user enters I love "Unix" and the contents of the... (2 Replies)
Discussion started by: srikanths
2 Replies

3. Shell Programming and Scripting

Search Replace with regular expressions

Hello I have this regular expression: </book>(?:\n)<collection>(.*)</collectioninfo> And I have this peace of text on a FILE <book bookid="3" title="the title 3" remaining = "50" price="100"> <reader readerid="1"><!]></reader> <reader readerid="2"><!]></reader> <reader... (1 Reply)
Discussion started by: dirdamalah
1 Replies

4. UNIX for Dummies Questions & Answers

Regular Expressions -- Find spaces outside

Hello, I need help with using grep and regular expressions.... I have a long list of about 1000 lines of Chinese flashcards. Here's a small excerpt: 意文 yìwén (given name) 貴姓 guìxìng (honorable surname) 貴 guì (honorable) 姓 xìng (one's surname is; to be surnamed; surname) 呢 ne (interrogative... (2 Replies)
Discussion started by: arduino411
2 Replies

5. Linux

A find and replace script

Hello everyone, I am trying to do a simple script (shell or perl) for a bioinformatic problem, where I want to use a list from file2 and append this information to file1 (output). Example: File1 >Apple1 GAGACGATTTATATATAGAAGAGAG >Banana2 CAGAGAGAGAGACCCCCCCCCCCC File2 >Apple1 ... (2 Replies)
Discussion started by: herasj01
2 Replies

6. Shell Programming and Scripting

FIND w/ multiple expressions

For reference i am still a newb at scripting, but i have what i think is a complex issue. I need to run a FIND on / to identify all files and print them to >> $TEMPFILE I need to avoid MVFS I need to avoid /var/tmp/nastmp/ I was trying find / \( -type d -name nastmp -prune \) -a \( -fstype... (4 Replies)
Discussion started by: nitrobass24
4 Replies

7. Shell Programming and Scripting

Find 2 expressions then print in a single line

Guys, need help. I have a file that contains something like this: abc def ghi jkl I want to print the first and last line of the file and the output should be in a single line. so, output should be like this: abc jkl (3 Replies)
Discussion started by: solidhelix08
3 Replies

8. UNIX for Advanced & Expert Users

Using find and regular expressions

Hi Could you please advise how can one extract from the output of find . -name "*.c" -print only filenames in the current direcotry and not in its subdirectories? I tried using (on Linux x86_64) find . -name "*.c" -prune but it is not giving correct output. Whereas I am getting... (9 Replies)
Discussion started by: tinku981
9 Replies

9. Shell Programming and Scripting

Find and Replace in Shell script

Friends, I have more than 1000 lines in text file which needs to be converted as UPPERCASE by adding _ com.sun.url=www.sun.com com.ssl.port=808 com.ui.path=/apps/ssi Expected output com.sun.url=_COM.SUN.URL_ com.ssl.port=_COM.SSL.PORT_ com.ui.path=_COM.UI.PATH_ Thanks in... (4 Replies)
Discussion started by: baluchen
4 Replies

10. Shell Programming and Scripting

sed find multiple expressions plus next next line

Hello I am trying to write sed code where it will look through the text for lines with specific expression "Started by user" and when found, will also add the following line, and also lines with another expression "Finished:" sed -n '/Started by user/, +1p, /Finished:/'... (4 Replies)
Discussion started by: dlesny
4 Replies
FAIL2BAN-REGEX(1)						   User Commands						 FAIL2BAN-REGEX(1)

NAME
fail2ban-regex - test Fail2ban "failregex" option SYNOPSIS
fail2ban-regex [OPTIONS] <LOG> <REGEX> [IGNOREREGEX] DESCRIPTION
Fail2Ban reads log file that contains password failure report and bans the corresponding IP addresses using firewall rules. This tools can test regular expressions for "fail2ban". LOG: string a string representing a log line filename path to a log file (/var/log/auth.log) "systemd-journal" search systemd journal (systemd-python required) REGEX: string a string representing a 'failregex' filename path to a filter file (filter.d/sshd.conf) IGNOREREGEX: string a string representing an 'ignoreregex' filename path to a filter file (filter.d/sshd.conf) OPTIONS
--version show program's version number and exit -h, --help show this help message and exit -c CONFIG, --config=CONFIG set alternate config directory -d DATEPATTERN, --datepattern=DATEPATTERN set custom pattern used to match date/times --timezone=TIMEZONE, --TZ=TIMEZONE set time-zone used by convert time format -e ENCODING, --encoding=ENCODING File encoding. Default: system locale -r, --raw Raw hosts, don't resolve dns --usedns=USEDNS DNS specified replacement of tags <HOST> in regexp ('yes' - matches all form of hosts, 'no' - IP addresses only) -L MAXLINES, --maxlines=MAXLINES maxlines for multi-line regex. -m JOURNALMATCH, --journalmatch=JOURNALMATCH journalctl style matches overriding filter file. "systemd-journal" only -l LOG_LEVEL, --log-level=LOG_LEVEL Log level for the Fail2Ban logger to use -v, --verbose Increase verbosity --verbosity=VERBOSE Set numerical level of verbosity (0..4) --verbose-date, --VD Verbose date patterns/regex in output -D, --debuggex Produce debuggex.com urls for debugging there --print-no-missed Do not print any missed lines --print-no-ignored Do not print any ignored lines --print-all-matched Print all matched lines --print-all-missed Print all missed lines, no matter how many --print-all-ignored Print all ignored lines, no matter how many -t, --log-traceback Enrich log-messages with compressed tracebacks --full-traceback Either to make the tracebacks full, not compressed (as by default) AUTHOR
Written by Cyril Jaquier <cyril.jaquier@fail2ban.org>. Many contributions by Yaroslav O. Halchenko and Steven Hiscocks. REPORTING BUGS
Report bugs to https://github.com/fail2ban/fail2ban/issues COPYRIGHT
Copyright (C) 2004-2008 Cyril Jaquier, 2008- Fail2Ban Contributors Copyright of modifications held by their respective authors. Licensed under the GNU General Public License v2 (GPL). SEE ALSO
fail2ban-client(1) fail2ban-server(1) fail2ban-regex 0.10.2 January 2018 FAIL2BAN-REGEX(1)
All times are GMT -4. The time now is 03:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy