sed inside the awk script to replace a string in the array
The requirement is i need to find an array value matching with pattern {5:{ , replace that with 5: and reassign that to same array index and print it.
I write something like below and the issue is sed command is not working. If i replace " with "`" the script gives syntax error.how can i achieve this?
sample :
Output:
Moderator's Comments:
Please use CODE tags when displaying sample input, sample output, and code segments.
Last edited by Don Cragun; 08-27-2019 at 09:32 PM..
Reason: Add CODE and ICODE tags
With what you have shown us, we have to do a lot of guessing to try to figure out what might be going wrong. Please, whenever you start a thread, tell us what operating system and shell you're using. And, when showing us a fragment of an awk script with associated diagnostic messages, indicate which line of the code you have shown us is the one that the diagnostic refers to (in this case, which line is line #180).
First, use /usr/xpg4/bin/awk or nawk; not awk when you're using any Solaris/SunOS system. (I strongly recommend /usr/xpg4/bin/awk since it meets all of the POSIX standard's requirements.)
Second, while sed uses Basic Regular Expressions (BREs), awk uses Extended Regular Expressions (EREs). And, in EREs, the opening brace character ({) is special and needs to be escaped when you are looking for a literal opening brace character. The code rdrtx1 suggested may work on some systems, but is not portable and (according to the standards) produces undefined behavior.
Third, since you are looking for a single occurrence of the string {5:{, there is no need to use gsub() (which looks for and attempts to find and replace as many occurrences of a matching pattern as it can find).
Try this instead:
Note that I also moved the i++ into the for statement instead of hiding the loop increment in your print statements and I moved the print statement out of both branches of the if statement so it is more obvious that the same print is needed whether or not a match is found.
I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: -->
cat comp.pkglist
Package list: nss-util-devel-3.28.4-1.el6_9.x86_64
Version Change: 3.28.4 -->... (1 Reply)
Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file:
</member>
<member>
<name>TransactionID</name>
<value><string>123456789123456</string></value>
</member>
<member>
<name>Number</name>
... (9 Replies)
Hi guys
Let me at first describe the whole thing that I'm trying to do. Lets say I have 100 files like the following one.
Ow 1230 16.000000 -0.834000 16.083957
1.751652398 -17.20094528 -4.450623277
Hw 1231 ... (6 Replies)
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)
Hi experts,
In my text file I have the following alot of lines like below.
input.k is as follows.
2684717 -194.7050476 64.2345581 150.6500092 0 0
2684718 -213.1575623 62.7032242 150.6500092 0 0
*INCLUDE
$# filename... (3 Replies)
hi experts ,
I have an input like following.
R sfst 1000.0000
$ new time step for mass scaled calculation
R dt2ms -4.000E-7
$ friction value for blank
R mue ... (10 Replies)
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)
Need help with either sed or awk to acheive the following
file1
-----
In the amazon forest
The bats eat all the time...
mon tue wed they would eat berries
In the tropical forest
The bats eat all the time...
on wed bats eat nuts
In the rain forest
The bats eat all the time...
on... (2 Replies)
Source File:
abcdefghijklmnop01qrstuvwxyz
abcdefghijklmnop02qrstuvwxyz
abcdefghijklmnop03qrstuvwxyz
abcdefghijklmnop04qrstuvwxyz
abcdefghijklmnop05qrstuvwxyz
Whatever characters are in 17-18 on each line of the file, it should be concatenated to the same line at the character number... (6 Replies)
Hello,
I really would appreciate some help with a bash script for some string manipulation on an SQL dump:
I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump.
This is quite easy with sed:
sed -e... (1 Reply)