Sponsored Content
Top Forums Shell Programming and Scripting Issue with sed command does not replace exact string matched Post 303020059 by mohtashims on Thursday 12th of July 2018 01:05:14 PM
Old 07-12-2018
Hammer & Screwdriver

Quote:
Originally Posted by Corona688
That it worked partially is very strange. Show the input you had, the output you were expecting, the output you got, and the exact code and regex file you used.
Input or original file proxy.log
Quote:
including its 190.169.11.15 configuration, runtime artifacts 190.169.11.155 such as >190.169.11.15< lock databases.
Expected output:
Quote:
including its 10.4.112.240 configuration, runtime artifacts 190.169.11.155 such as >10.4.112.240< lock databases.
as you can see only 2/3 string "190.169.11.15" should be replaced.

The one which should not get replaced is 190.169.11.155 because it is followed by / preceded by a numeric digit(see red bold)

Current i am getting the below output:
Quote:
including its 190.169.11.15 configuration, runtime artifacts 190.169.11.155 such as >190.169.11.15< lock databases.
As you can see nothing got replaced Smilie

more change.sed
Code:
s=\(^\| \)190.169.11.15\($\| \)=\110.4.112.240\2=g

My command is sed -f change.sed proxy.log
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SED: delete and print the only exact matched pattern

I am really need help with the regular expression in SED. From input file, I need to extract lines that have the port number (sport or dport) as defined. The input file is something like this time=1209515280-1209515340 dst=192.168.133.202 src=208.70.8.23 bytes=2472 proto=6 sport=80 dport=1447... (6 Replies)
Discussion started by: new_buddy
6 Replies

2. Shell Programming and Scripting

Urgent help needed !!!....to replace a exact string

Hi experts, As i am a novice unix player...so need help for the below query...banged my head from quite a while...:confused: i have a set of html files, in which i need to search for string "Page"(case sensitive) and then replace the same with some numeric code ,say, "XXX1234". Here in... (1 Reply)
Discussion started by: rahulfhp
1 Replies

3. Shell Programming and Scripting

search and replace exact string

Hello Everyone, Im trying to run a search and replace of exact strings and the strings that im using variables that are passed through an array in a while loop. Here is a snip of my code: USEROLD=`cat oldusers` USERNEW=`cat newusers` USEROLDARRAY=( $USEROLD ) USERNEWARRAY=( $USERNEW )... (4 Replies)
Discussion started by: skizim
4 Replies

4. Shell Programming and Scripting

How to use SED or AWK to search and replace an exact string

I have a file DS1 DDS DS I want to replace only "DS" to "DSmail.blah.com" in a lot of files. I tried sed 's/DS/DSmail.blah.com' but it changes all the lines . thanks in advance (2 Replies)
Discussion started by: gubbu
2 Replies

5. Shell Programming and Scripting

sed get matched string

Hi, how to figure out script name from a file which are having pattern .ksh. So wherever i have .ksh in a file i should get complete name of the file along with its extension as well. (7 Replies)
Discussion started by: vinsin55
7 Replies

6. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

7. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

8. UNIX for Dummies Questions & Answers

Replace backslash at the end of the string using sed command

I have text file which is a tab delimited one. Sample data from the file is shown below: unix is\ great\ os linux\ is superb I want to replace that backslash with empty string preserving the tab delimiter. Output should be unix is great os linux is ... (3 Replies)
Discussion started by: p.akhilreddy4u
3 Replies

9. Shell Programming and Scripting

How to search and replace string in column in file with command sed?

how to search and replace string in column in file with command sed or other search "INC0000003.in" and replace column 4 = "W" $ cat file.txt INC0000001.in|20150120|Y|N|N INC0000002.in|20150120|Y|N|N INC0000003.in|20150120|Y|N|N INC0000004.in|20150120|Y|N|Noutput... (4 Replies)
Discussion started by: ppmanja3
4 Replies

10. Shell Programming and Scripting

Match exact String with sed command

I have a workaround to the problem i m posting, however if someone wants to look at my query and respond ... i will appreciate. This is in reference to this thread -> https://www.unix.com/shell-programming-and-scripting/267630-extract-between-two-exact-matched-strings.html I have data.txt as... (11 Replies)
Discussion started by: mohtashims
11 Replies
NETWORKCTL(1)							    networkctl							     NETWORKCTL(1)

NAME
networkctl - Query the status of network links SYNOPSIS
networkctl [OPTIONS...] COMMAND [LINK...] DESCRIPTION
networkctl may be used to introspect the state of the network links as seen by systemd-networkd. Please refer to systemd- networkd.service(8) for an introduction to the basic concepts, functionality, and configuration syntax. OPTIONS
The following options are understood: -a --all Show all links with status. -h, --help Print a short help text and exit. --version Print a short version string and exit. --no-legend Do not print the legend, i.e. column headers and the footer with hints. --no-pager Do not pipe output into a pager. COMMANDS
The following commands are understood: list [LINK...] Show a list of existing links and their status. If no further arguments are specified shows all links, otherwise just the specified links. Produces output similar to: IDX LINK TYPE OPERATIONAL SETUP 1 lo loopback carrier unmanaged 2 eth0 ether routable configured 3 virbr0 ether no-carrier unmanaged 4 virbr0-nic ether off unmanaged 4 links listed. status [LINK...] Show information about the specified links: type, state, kernel module driver, hardware and IP address, configured DNS servers, etc. When no links are specified, an overall network status is shown. Also see the option --all. Produces output similar to: State: routable Address: 10.193.76.5 on eth0 192.168.122.1 on virbr0 169.254.190.105 on eth0 fe80::5054:aa:bbbb:cccc on eth0 Gateway: 10.193.11.1 (CISCO SYSTEMS, INC.) on eth0 DNS: 8.8.8.8 8.8.4.4 lldp [LINK...] Show discovered LLDP (Link Layer Discovery Protocol) neighbors. If one or more link names are specified only neighbors on those interfaces are shown. Otherwise shows discovered neighbors on all interfaces. Note that for this feature to work, LLDP= must be turned on on the specific interface, see systemd.network(5) for details. Produces output similar to: LINK CHASSIS ID SYSTEM NAME CAPS PORT ID PORT DESCRIPTION enp0s25 00:e0:4c:00:00:00 GS1900 ..b........ 2 Port #2 Capability Flags: o - Other; p - Repeater; b - Bridge; w - WLAN Access Point; r - Router; t - Telephone; d - DOCSIS cable device; a - Station; c - Customer VLAN; s - Service VLAN, m - Two-port MAC Relay (TPMR) 1 neighbors listed. label Show numerical address labels that can be used for address selection. This is the same information that ip-addrlabel(8) shows. See RFC 3484[1] for a discussion of address labels. Produces output similar to: Prefix/Prefixlen Label ::/0 1 fc00::/7 5 fec0::/10 11 2002::/16 2 3ffe::/16 12 2001:10::/28 7 2001::/32 6 ::ffff:0.0.0.0/96 4 ::/96 3 ::1/128 0 EXIT STATUS
On success, 0 is returned, a non-zero failure code otherwise. SEE ALSO
systemd-networkd.service(8), systemd.network(5), systemd.netdev(5), ip(8) NOTES
1. RFC 3484 https://tools.ietf.org/html/rfc3484 systemd 237 NETWORKCTL(1)
All times are GMT -4. The time now is 03:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy