Issue with sed command does not replace exact string matched


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue with sed command does not replace exact string matched
# 15  
Old 07-12-2018
Your reports are inconsistent. It's possible that your version of sed doesn't support the extended syntax -- but then it shouldn't ever have worked at all, not just missed a few things inside >< brackets.
# 16  
Old 07-12-2018
Do you have GNU sed on your system? (gsed) Or perl?
# 17  
Old 07-12-2018
Hammer & Screwdriver

Quote:
Originally Posted by Corona688
Do you have GNU sed on your system? (gsed) Or perl?
I do have perl but I usually avoid perl as I m not at all familiar. Also perl is less likely to be on every server I use my scripts as compared to sed.

Code:
bash-3.2$ file /usr/xpg4/bin/sed
/usr/xpg4/bin/sed:      ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped
bash-3.2$ which sed
/usr/bin/sed
bash-3.2$ gsed
bash: gsed: command not found

I tried using /usr/xpg4/bin/sed however, does not replace the strings either.
# 18  
Old 07-12-2018
How about awk?
Code:
awk '{for (i=1; i<=NF; i++) if ($i==from) $i=to; print}' from=190.169.11.15 to=10.4.112.240 < proxy.log

Or
Code:
cat changefile
190.169.11.15 10.4.112.240

awk 'FILENAME!="-" {A[$1]=$2; next} {for (i=1; i<=NF; i++) if (A[$i]!="") $i=A[$i]; print}' changefile - < proxy.log

The (A[$i]!="") is clumsy and can consume extra memory but supports Solaris /bin/awk.
Better is ($i in A). Then Solaris needs nawk or /usr/xpg4/bin/awk
You can add more lines to changefile...
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question