Sponsored Content
Top Forums Shell Programming and Scripting sed - replacing a substring containing a hyphen Post 302955551 by squrcles on Friday 18th of September 2015 12:12:05 PM
Old 09-18-2015
sed - replacing a substring containing a hyphen

I'm attempting to replace a substring that contains a hyphen and not having much success, can anyone point out where i'm going wrong or suggest an alternative.

Code:
[root@localhost kvm]#  echo /var/lib/libvirt/images/vm888b-clone.qcow | sed -e 's|vm888-clone|qaz|g'
/var/lib/libvirt/images/vm888b-clone.qcow


Last edited by vbe; 09-18-2015 at 01:36 PM.. Reason: square brackets for code tags... hehe...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed extract substring on (OS X)

On OS 10.4.11 I have filenames like: 670711 SA T2 v1-1_DS_EF.doc CT_670520 AM T1 v1-2_DS_EF.doc CT_670716 - 2 SA T4 v1-2_DS_EF.doc CT_670713 SA T3 v1-1_DS_EF.doc 670421 PA DYP1 v1-1_DS_EF.doc CT_670425 PA DYP2 v1-1_DS_EF.doc CT_670107 RA T3 v1-2_DS_EF.doc CT_670521 AM T2 v1-2_DS_EF.doc... (3 Replies)
Discussion started by: mlommel
3 Replies

2. Shell Programming and Scripting

Using sed to get a substring

Hi, I have looked all over for this. I am attempting to get a the substring of a string using sed since it seemed the best solution for this. For example my string is: "zzz foo to you and bar123 or foo" I would like to extract the text between "and" and "or" (it could be anything, but... (2 Replies)
Discussion started by: CentaurAtlas
2 Replies

3. Shell Programming and Scripting

Substring using sed or awk

I am trying to get a substring from a string stored in a variable. I tried sed with a bit help from this forum, but not successful. Here is my problem. My string is: "REPLYFILE=myfile.txt" And I need: myfile.txt (everything after the = symbol). My string is: "myfile.txt.gz.20091120.enc... (5 Replies)
Discussion started by: jamjam10k
5 Replies

4. Shell Programming and Scripting

Sed and SubString

Hi Folks, I am here with a simple doubt. I am having a flat file in which I want to replace the characters from say 5 to 15 as some text. Flat file contains a single line. For example 01MRRAJESH21000RAJESH INDUSTRIES In the above line pos 16-21 is Rajesh, I want to search for the... (4 Replies)
Discussion started by: dinesh1985
4 Replies

5. Shell Programming and Scripting

Making substring with sed

Input: You can easily do this by highlighting your code. How can i get the substring from index 9 to 12 using sed? (6 Replies)
Discussion started by: cola
6 Replies

6. Programming

sed no match word end with hyphen

Hi, This is my first post.It has two parts first part: I want to match a line that starts with whitespace tab or similar followed by must start with specific word and not match same word start with hyphen like this: grep height file1: height: 150px; line-height: 1.5em; height:... (4 Replies)
Discussion started by: medium_linux
4 Replies

7. Shell Programming and Scripting

Replacing a string with its substring

Hi All, Below is some sample content of my input file: There are many types and traditions of anarchism, some of which are ]. Strains of anarchism have been divided into the categories of ] and ] or similar dual classifications. Anarchism is often considered to be a radical ] ideology, and... (8 Replies)
Discussion started by: satheeshkumar
8 Replies

8. Shell Programming and Scripting

Substring Problem with sed . . .

Greetings. I'm looking to isolate the first occurrence of an arbitrary substring which may be present at any particular line in a given file. The enclosing end markers for the target in our thought problem are string" and ". The complete string and surrounding text could look something like... (3 Replies)
Discussion started by: LinQ
3 Replies

9. Shell Programming and Scripting

Insert a hyphen between two delimiters using sed

Hey guys, I have a file that is delimited by | and I am trying to write a sed command to convert this: abc|def||ghi|jkl||||mnop into this: abc|def|-|ghi|jkl|-|-|-|mnop The output I am getting out of: sed -e "s/+//g" /tmp/opt.del > /tmp/opt2.del is like: ... (9 Replies)
Discussion started by: prohank
9 Replies

10. Shell Programming and Scripting

Replacing space with hyphen in a pattern.

I have a huge text file, about 52 GB. In the file, there are patterns like these: ] ] ] ]One can see that there is text within patterns such as and ], and I am only interested in ]. There is text before and after all these patterns too, for example, ''Anarchism''' is a ] that advocates ]... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies
STAPVIRT(1)						      General Commands Manual						       STAPVIRT(1)

NAME
stapvirt - prepare libvirt domains for systemtap probing SYNOPSIS
stapvirt [-c URI] [-d PATH] [-v] COMMAND ARGUMENTS DESCRIPTION
The stapvirt program can be used to add ports to domains managed by libvirt (see <http://libvirt.org/>). These ports can then be used by stap to run scripts inside the domains (see the '--remote' option in stap(1) for more information). Starting from libvirt v1.1.1 and QEMU v0.10.0, SystemTap ports can be hotplugged and thus domains do not require any preparation using stapvirt. The 'query' command can be used to determine whether hotplugging is supported. If hotplugging is not supported, then ports must be added to the definition of the domain using the 'port-add' command. These ports can later be removed using the 'port-remove' command. Note that there can only be as many simultaneous stap sessions as there are ports. OPTIONS
The following options are supported. Any other option prints a short help message. -c URI Specify the libvirt driver URI to which to connect (e.g. 'qemu:///system'). The default value is NULL, which indicates to libvirt to connect to the default driver. See the page at <http://libvirt.org/uri.html> for supported values. -d PATH Specify the directory in which UNIX sockets should be created when SystemTap ports are added. The default directory is '/var/lib/libvirt/qemu'. -v Increase verbosity. This option may be repeated for more verbosity. COMMANDS
The following commands are recognized by stapvirt. Any other command prints a short help message. help Display the help message. list List available domains. port-add DOMAIN Add a permanent SystemTap port to the domain's definition. If the domain is currently running, it must be restarted before changes take effect. port-list DOMAIN List the UNIX socket paths of the permanent SystemTap ports in the domain's definition. port-remove DOMAIN Remove a permanent SystemTap port from the domain's definition. If the domain is currently running, it must be restarted before changes take effect. query DOMAIN Display the following information about the domain: its name, its UUID, its state, the number of permanent SystemTap ports in- stalled, and whether hotplugging is supported. TUTORIAL
This tutorial will help you get started with stapvirt. Let's start by listing all the privileged domains on the machine with the list com- mand: $ stapvirt -c 'qemu:///system' list Available domains on URI 'qemu:///system': ID State Type Name 2 running persistent TestVM Note that we specified the libvirt URI using the -c switch. Otherwise libvirt might have defaulted to e.g. 'qemu:///session'. Rather than typing the URI everytime, it might be easier to instead set the LIBVIRT_DEFAULT_URI environment variable and omit the -c switch. Note that this is a libvirt functionality (see <libvirt.org/uri.html> for more details). The list command indicates that we have a running domain named 'TestVM' with ID 2. Let's use the query command to retrieve more informa- tion: $ stapvirt query TestVM # by name $ stapvirt query 2 # by ID Name: TestVM UUID: 905951c0-fa4f-409b-079c-c91ddda27028 State: running ID: 2 Type: persistent Permanent Ports: 0 Hotplugging: not supported The query command gives us some basic information about the domain, such as its name, UUID, and state. More importantly, it gives us two pieces of information: the number of permanent ports installed, and whether hotplugging is supported. Technically, hotplugging support de- pends on libvirt and qemu, and is not related to the domain in itself. If hotplugging were supported, we could stop here and run stap directly. Since in our case hotplugging is not supported, we need to add SystemTap ports. To do this, we use the port-add command: $ stapvirt port-add TestVM Added new port org.systemtap.stapsh.0 The domain must be restarted before changes take effect. We can confirm that a port was added by running the query command again: $ stapvirt query TestVM ... Permanent Ports: 1 Hotplugging: not supported It now indicates that there is 1 permanent port. We can also use the port-list command to know exactly where the port will be created: $ stapvirt port-list TestVM /var/lib/libvirt/qemu/TestVM.org.systemtap.stapsh.0.sock After stopping and restarting the domain, we are now ready to use the port with stap: $ stap -e 'probe begin { printf("Hello from TestVM! "); exit() }' --remote=libvirt://TestVM Hello from TestVM! Finally, if we'd like to remove the port, we can use the port-remove command: $ stapvirt port-remove TestVM Removed port org.systemtap.stapsh.0 The domain must be restarted before changes take effect. And that's all there is to it! SEE ALSO
stap(1) BUGS
Use the Bugzilla link of the project web page or our mailing list. http://sourceware.org/systemtap/,<systemtap@sourceware.org>. STAPVIRT(1)
All times are GMT -4. The time now is 09:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy