1. The sed command and it's flags
- The -r tells sed to use regex-extended matching.
2. The search pattern
- (.*)\/(.*)
- \/ is the escaped form of /
- We escape the '/' since sed sees '/' as a search pattern delimiter
3. The replace pattern
- \1\/\2 \1 \2
- \/ is the escaped form of /
- We escape the '/' since sed sees '/' as a search pattern delimiter
4. The sed commands
- 's' at the start
- This tells sed that we are searching and replacing
- The character following s used as the pattern delimiter
- You can make the delimiter what ever you like (|, /, :, ^, etc...)
- 'g' at the end
- This tells sed to match more than one occurrence per line if found
- If not used and the line has multiple occurrences of pattern only 1 is matched and replaced
The (.*)\/(.*) says match everything but keep the parts before and after the / (which is escaped as \/) for later use.
In the replace pattern of the search we use \1 and \2 several times along with the escaped / (\/) again.
\1 is the first item we kept from the search (everything to the left of '/' or www.google.com)
\2 is the second part we kept (everything to the right of '/' or sample.log) .
So '\1\/\2 \1 \2' becomes 'www.google.com/sample.log www.google.com sample.log'
Last edited by ddreggors; 04-29-2011 at 12:28 PM..
These 2 Users Gave Thanks to ddreggors For This Post:
Like ddreggors have mentioned we can use any other character as a delimiter instead of "/" in sed. This will help in avoiding confusion if we have "/" in the string we are using. Below is a slightly modified code using "!" as delimiter.
Hi,
I'm not real familiar with sed, but I need to capture the year this directory path. Here's what I have so far. I'm able to capture the run name, but I want the only the year that's within the run name. How can I do this?
... (3 Replies)
Hi
I am having hard time getting this right and need some help. I Have 3 files, and everyone contains the following:-
File1
Today, we have Name(Jack) Age(19) Class (A2)
Today, we have Name(Kim) Class (G9)
File2
Today, we have Name(Lee) Age(19) Class (A2)
Today, we have... (8 Replies)
Hi,
I want to know the os name via c/c++ source code.so please help me to do the same.
I will appreciate if anyone can provide me the source code.
Thanks in advance.. (9 Replies)
Guys I need your help...
I receive the month and the day in a file and I keep it in a variable. I need to take this day that Iīve kept compare with the current day and pick the file to the next day...
Letīs say I receive a file 27-JUL-2007 and I need to check in the system the current day and... (2 Replies)
Hi,
I am new to unix.
I have a file with records like the below
ads-sap-4.txt: </a></b></span><span class="linkbutton yellow_but"><a id="2005754_more" style="cursor:pointer; cursor:hand;"... (3 Replies)
I am trying to capture the file name(which is not of fixed length) and put it in a variable. It is working in unix whereas when I am running the same script in Informatica it is not giving me the desired output. But when I comment the option(find the file name) then it is working fine. It can... (4 Replies)
I'm trying to capture the files that this command types out, but i'm not able to do it. I'm pipeing everything to the telnet command because if i dont the connection closes. Any suggestions.
#!/bin/ksh
hostn='x.x.x.xx xxxx'
(echo "open $hostn\r"
sleep 3
echo " \r"
sleep 2
(echo... (3 Replies)
hello
I need for a script to capture the ip address from the connected user.
I have 5 logical partitions.
With "who", i have the ip adress, but only for 2 servers.
Do you know another command to know the ip address of connected clients ?
thank you (14 Replies)
Hi,
my perl script is calling another external java program. The Java in turn prints out a string. how can I capture the string.
------------------
#!/usr/bin/perl
print "Content-type:text/html\n\n";
use CGI;
$query = new CGI;
$theCookie = $query->cookie('someCookie');
$user =... (0 Replies)