Sponsored Content
Top Forums Shell Programming and Scripting Automating find and replace REGEX expressions in a script Post 303045354 by balajesuri on Wednesday 18th of March 2020 01:09:59 AM
Old 03-18-2020
You may try perl. When it comes to regex and string parsing, perl handles them beautifully. Of course, doesn't mean you don't have other options.
This User Gave Thanks to balajesuri For This Post:
 

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
GIT-REPLACE(1)							    Git Manual							    GIT-REPLACE(1)

NAME
       git-replace - Create, list, delete refs to replace objects

SYNOPSIS
       git replace [-f] <object> <replacement>
       git replace [-f] --edit <object>
       git replace [-f] --graft <commit> [<parent>...]
       git replace -d <object>...
       git replace [--format=<format>] [-l [<pattern>]]

DESCRIPTION
       Adds a replace reference in refs/replace/ namespace.

       The name of the replace reference is the SHA-1 of the object that is replaced. The content of the replace reference is the SHA-1 of the
       replacement object.

       The replaced object and the replacement object must be of the same type. This restriction can be bypassed using -f.

       Unless -f is given, the replace reference must not yet exist.

       There is no other restriction on the replaced and replacement objects. Merge commits can be replaced by non-merge commits and vice versa.

       Replacement references will be used by default by all Git commands except those doing reachability traversal (prune, pack transfer and
       fsck).

       It is possible to disable use of replacement references for any command using the --no-replace-objects option just after git.

       For example if commit foo has been replaced by commit bar:

	   $ git --no-replace-objects cat-file commit foo

       shows information about commit foo, while:

	   $ git cat-file commit foo

       shows information about commit bar.

       The GIT_NO_REPLACE_OBJECTS environment variable can be set to achieve the same effect as the --no-replace-objects option.

OPTIONS
       -f, --force
	   If an existing replace ref for the same object exists, it will be overwritten (instead of failing).

       -d, --delete
	   Delete existing replace refs for the given objects.

       --edit <object>
	   Edit an object's content interactively. The existing content for <object> is pretty-printed into a temporary file, an editor is
	   launched on the file, and the result is parsed to create a new object of the same type as <object>. A replacement ref is then created
	   to replace <object> with the newly created object. See git-var(1) for details about how the editor will be chosen.

       --raw
	   When editing, provide the raw object contents rather than pretty-printed ones. Currently this only affects trees, which will be shown
	   in their binary form. This is harder to work with, but can help when repairing a tree that is so corrupted it cannot be pretty-printed.
	   Note that you may need to configure your editor to cleanly read and write binary data.

       --graft <commit> [<parent>...]
	   Create a graft commit. A new commit is created with the same content as <commit> except that its parents will be [<parent>...] instead
	   of <commit>'s parents. A replacement ref is then created to replace <commit> with the newly created commit. See
	   contrib/convert-grafts-to-replace-refs.sh for an example script based on this option that can convert grafts to replace refs.

       -l <pattern>, --list <pattern>
	   List replace refs for objects that match the given pattern (or all if no pattern is given). Typing "git replace" without arguments,
	   also lists all replace refs.

       --format=<format>
	   When listing, use the specified <format>, which can be one of short, medium and long. When omitted, the format defaults to short.

FORMATS
       The following format are available:

       o   short: <replaced sha1>

       o   medium: <replaced sha1> -> <replacement sha1>

       o   long: <replaced sha1> (<replaced type>) -> <replacement sha1> (<replacement type>)

CREATING REPLACEMENT OBJECTS
       git-filter-branch(1), git-hash-object(1) and git-rebase(1), among other git commands, can be used to create replacement objects from
       existing objects. The --edit option can also be used with git replace to create a replacement object by editing an existing object.

       If you want to replace many blobs, trees or commits that are part of a string of commits, you may just want to create a replacement string
       of commits and then only replace the commit at the tip of the target string of commits with the commit at the tip of the replacement string
       of commits.

BUGS
       Comparing blobs or trees that have been replaced with those that replace them will not work properly. And using git reset --hard to go back
       to a replaced commit will move the branch to the replacement commit instead of the replaced commit.

       There may be other problems when using git rev-list related to pending objects.

SEE ALSO
       git-hash-object(1) git-filter-branch(1) git-rebase(1) git-tag(1) git-branch(1) git-commit(1) git-var(1) git(1)

GIT
       Part of the git(1) suite

Git 2.17.1							    10/05/2018							    GIT-REPLACE(1)
All times are GMT -4. The time now is 04:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy