5

Try also sed 's/\(Jacquelin\)e\?/\1e/g' file or sed -r 's/(Jacquelin)e?/\1e/g' file


5

The command to find files matching certain criteria is find. If you want to search in the current directory, all you need is: find -name '*.part' To limit it to files only (no directories or any other type of result), use: find -type f -name '*.part' Alternatively, with bash you could do: shopt -s globstar echo **/*.part The globstar option is ...


2

use this to get your pattern sed ':begin;$!N;s/\n/ /;tbegin' file.txt | sed 's/ /\n/g'


2

You should be able to accomplish this using awk, by operating it in "paragraph mode" (see e.g. @EdMorton's solution here and a solution to the "print all but the first fields" problem from stackoverflow) awk -v RS= -F'\n' '{$1=$2=""; print $0}' file.srt > file.txt This will interpret any blocks of "empty line"-separated text as one input record, whose ...


2

Since your Operating System (FreeBSD) comes with a compiler and a lexer by default (just like any Unix system should), better use them to write a little program, rather than some ass-fugly regexes that nobody will ever be able to understand. $ cat > ipv46.l <<'EOT' %{ #include <sys/socket.h> #include <netinet/in.h> #include <arpa/...


2

Alternative non-grep, perl based approach using the Regexp::Common package (Available as a FreeBSD port under the name p5-Regexp-Common): perl -MRegexp::Common=net -nE 'say $& while /$RE{net}{IPv4}|$RE{net}{IPv6}/g' input.txt Example: $ cat input.txt some words a line with 127.0.0.1 and 192.168.1.1 in it. more words some line with ::1 in it. $ perl -...


2

Finding the discrepancy I spent some time poking through the source code for grep and narrowed down the problem a bit. The main issue lies in the function print_line_middle. See this loop construct: for (cur = beg; (cur < lim && ((match_offset = execute (compiled_pattern, beg, lim - beg, &...


2

I would recommend using Perl to utilise negative look-aheads perl -pe 's/Jacquelin(?!e)/Jacqueline/g' which will replace when Jacquelin is not immediately followed by the character e (this includes if there isn't a character after) To batch edit files in-place, you can add the -i flag: find . -name '*' -type f -exec perl -pi -e 's/Jacquelin(?!e)/...


2

Using awk on the command line: $ awk 'BEGIN { print "const Ipp32fc complexes[] = {" } END { print "};" } { re=im=$0; sub("[+-][0-9.]*i$", "", re); sub("^-?[0-9.]*", "", im); sub("i$", "", im); printf "\t{ %s, %s },\n", re, im }' file const Ipp32fc complexes[] = { { -0.0272780, +88932190 }, { 0.2833029, -10293882 }, { 0.1990238, +...


1

The back-reference \1 is missing the corresponding subexpression: sed -n -e 's/^.*\(Word1 word2\)/\1/p' file1.txt > newfile.txt The brackets group together Word1 word2 so that it can be used as \1 in the replacement If the -E (--regexp-extended) option were used, the brackets wouldn't require the preceding \ Also note that this actually deletes all text ...


1

In sed (easier for me to test in it), we can build the regex needed. A [^ ]* should match any word (if there are no punctuation characters). So: $ a="Abbey Street E.2 Buckfast Street" $ echo "$a" | sed 's/[^ ]*//' Street E.2 Buckfast Street will remove the first word. Note that the space has been left in the output. We need then to remove the space as ...


1

One solution with pcregrep which stands for Perl Compatible Regular Expressions GREP. pcregrep -M "^except:\n\s+pass$" file where -M, --multiline allows patterns to match more than one line. The regular expression matches the literal :except: at the beginning of a line followed by a line break, 0 or more white spaces (matching the most amount possible) ...


1

Given your example, something like this should work: $ cat ex #multiline.pattern: ^\[ $ sed -e "s/^#multiline\.pattern:.*/multiline.pattern: '^\\\['/" ex multiline.pattern: '^\[' That replaces a line that starts with #multiline.pattern: followed by any number of characters to the end of the line with the pattern you're after. The pattern you're after ...


1

In your sed commands cited as "Original string", you seem to use U+201C “ e2 80 9c LEFT DOUBLE QUOTATION MARK U+201D ” e2 80 9d RIGHT DOUBLE QUOTATION MARK in lieu of the " (0x22) ASCII character. Which neither sed nor shell will recognize. Try using a *nix text editor.


1

It's a good habit to single-quote your sed expressions, unless you know you want shell expansion of, for example, $d. sed sees your final expression as sed "/^" if the shell variable $d is unset. (For future debugging purposes, you could've run sed "(your expression)" usdeclar.txt for each of your expressions in turn, to find which of them was giving you ...


1

The Positive (?=) and Negative lookahead (?!) assertions work well only in a tool that supports PCRE extensions. Neither GNU sed nor POSIX support these library extensions. You need perl which supports it out of the box perl -pe 's/bbbb11.*?(?= )//' Or you can very well achieve the same without the regex support. For such trivial substitutions you can do ...


1

With GNU awk for FPAT (and then, since we already require gawk, also using gensub() and \s shorthand for [[:space:]]): $ cat tst.awk BEGIN { FPAT = "([^,]*)|(\"[^\"]+\")" OFS="," } { name = gensub(/^"|"$/,"","g",$1) n = split(gensub(/^"|"$/,"","g",$2),emails,/\s*[;,|:]\s*/) for (i=1; i<=n; i++) { print name, emails[i] } } $...


1

The problem is that hdisk...SVC occurs twice in the line, and .* is greedy. If you have GNU grep, you can use the -P option to get non-greedy matching: grep -oP '(?<=hdisk).+?(?=SVC)' file | sort -u outputs crs01 crs02 crs03 data01 data02 data03 data04 data05 data06 data12 data13 data14 data15 data16 data17 data18 data19 data20 data21 data22 data23 ...


1

If you want to run a substitution again and again as long as it succeeds, that can be done in sed with a conditional loop using the t command: grep -ErlIZ -- '<OldPattern>' . | xargs -r0 sed -Ei -e :1 -e 's/<OldPattern>/<NewPattern>/g' -e t1 Here also passing as many files as possible to sed instead of running one sed per file for ...


Only top voted, non community-wiki answers of a minimum length are eligible