Hi stomp,
You are correct in noting that some shells (including recent versions of bash and ksh93) can use ((cnt++)) as a shortcut for cnt=$((cnt+1)) and MadeInGermany's suggestion of cnt=$((cnt+=1)) and can also use last=${var: -1} as a shortcut for RudiC's suggestion of last=${var#${var%?}} to get the last character from the expansion of $var, but more shells (in fact any POSIX-conforming shells) support arithmetic expansions ($((expression))), and the ${var#pattern} and ${var%pattern} parameter expansions. The arithmetic command (((expression))) and the substring parameter expansions (${var:offset} and ${var:offset:length}) are extensions allowed, but not defined by the standards, and are not provided by as many shells.
But, I don't know of any shell where cnt=$((cnt++)) is required to be the same as cnt=$((cnt+1)) because the order in which a post-increment operation on a variable and an assignment to the same variable happens is unspecified. In both ksh (version: (AT&T Research) 93u+ 2012-08-01) and bash (version: 3.2.57(1)-release (x86_64-apple-darwin15)), the commands:
produce the output:
Imagine the sequence of operations of cnt=$((cnt++)) as:
save the value of cnt (1),
increment the value of cnt to 2
return the saved value (1) as the result of the arithmetic expansion, and
finally, assign the returned value to cnt (negating the post-increment).
But, it could also be processed as:
save the value of cnt (1),
return the saved value (1) as the result of the arithmetic expansion,
assign the returned value to cnt, and
finally, increment the value of cnt to 2.
You have exactly the same problem in C and C++ with:
Building it on some systems gives the warning:
and, when run, producing the output:
or:
(But, on the system I'm currently using, it always produces just 1s as the output.)
This User Gave Thanks to Don Cragun For This Post:
Hi Forum.
I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script.
Any feedback will be greatly appreciated.
... (19 Replies)
Hi All,
I am trying to replace the values inside <password> tag in an xml file but it doesn't replace certain passwords:
For eg:
Server/home/sperinc>cat TextXML.txt
<appIds>
<entry name="AccountXref">
<type id="ldap">
<realm>nam</realm>
... (7 Replies)
I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help
File:
<xml><object1>house</object1><object2>child</object2>... (9 Replies)
As per the requirement I need to replace XML tag with old to new on one of the XML file.
Old<com : DEM>PHI</com : DEM>
New<com : DEM>PHM</com : DEM>
Please someone provide the sed command to replace above mentioned old XML tag with new XML tag (2 Replies)
Hi Guys
Here is my Input :
<?xml version="1.0" encoding="UTF-8"?>
<xn:MeContext id="01736">
<xn:VsDataContainer id="01736">
<xn:attributes>
<xn:vsDataType>vsDataMeContext</xn:vsDataType>
... (12 Replies)
Hi all,
I basically want to remove certain characters from within a certain XML tag:
From:
<mytagone>hello 1-2-3 world</mytagone>
<mytagtwo>hello 1-2-3 world</mytagtwo>
To:
<mytagone>hello 1 2 3 world</mytagone>
<mytagtwo>hello 1-2-3 world</mytagtwo>
Is this possible using sed... (6 Replies)
Hi All,
Find the following code:
<Universal>D38x82j1JJ
</Universal>
I want to retrieve the value of <Universal> tag as below:
Please help me. (3 Replies)
Hi,
I have an XML file with around 1 billion rows in it and i am trying to find the number of times a particular tag occurs in it. The solution i am using works but takes a lot of time (~1 hr) .Please help me with an efficient way to do this.
Lets say the input file is
<Root>
... (13 Replies)
Hi All,
I have xml file,i am tring to use awk to search pattern as: <Password>x</Password>
and Replace with:
<Password>y</Password>
please any one can help to solve this using awk and awk only. (4 Replies)
Hi,
Can someone help me come up with a generic sed command to clean a tag off its attributes?
For eg.
Input String - <tag attrib=new>This String</tag>
should undergo a sed transformation to get
Output String - <tag >This String</tag>
This works -
echo "<tag attrib=new>This</tag>" |... (3 Replies)