I would like to convert the following piece of code from bash to awk.
Here are bash variables in a bash script.
CUR_ROW_ID and ROW_ID_TO_SEARCH contains a string which represent a row id.
The string contain a valid row id.
CUR_ROW_ID sometimes may be null.
CUR_VALUE contains a string which represent the value of the relative CUR_ROW_ID.
CUR_VALUE sometimes may be null.
DO_IT is a flag to control the rest of the process.
Three variables a read from bash env to awk env : CUR_ROW_ID and ROW_ID_TO_SEARCH and CUR_VALUE
One variable is write from awk env to bash env.
Don't look for a meaning in this piece of code. It's just a question about nested if-then-else
ROW_ID_TO_SEARCH contains a string to search in the input file
If there is a match CUR_ROW_ID = ROW_ID_TO_SEARCH
If ROW_ID_TO_SEARCH is not in the input file CUR_ROW_ID is null.
I got this in bash with something like : So my question is : how to convert the following in awk :
AWK part
To convert
I have tried this which does not work ( print all the line ) :
For nested if-the-else I have tried this which should not print nothing because "ROW_ID_TO_SEARCH" (FORCE_IGNORE9) is not in the input file
Not clear. The result you present is exactly what one would expect once your code has been rearranged like
If your search pattern is not found AND $2 holds a value, print that "ID_NOLT_NULL" - line.
What is your desire? What am I missing here?
Than k you for your quick posting.3
I have found this rules when googleing :
What I would like to do if possible is ( don't take care about the {} syntax; it is just to explain my thought) :
I would like to add a sub level block of if-then-else any where.
--- Post updated at 17:52 ---
Quote:
Originally Posted by RudiC
Not clear. The result you present is exactly what one would expect once your code has been rearranged like
If your search pattern is not found AND $2 holds a value, print that "ID_NOLT_NULL" - line.
What is your desire? What am I missing here?
To explain what i want I am going to use pseudo code so forget missing ';' or missing {} :
and the result should be now :
because the row id to search is not in the input file
... What I would like to do if possible is ( don't take care about the {} syntax; it is just to explain my thought) :
.
.
.
To explain what i want I am going to use pseudo code so forget missing ';' or missing {} :
That's EXACTLY the point - you CAN'T "forget missing ... {}". You HAVE to "take care about the {} syntax" as they support / convey the logics. action n in an if construct is a - one or multiple statement - block of code to be executed if the relevant condition is true. Inside the block, you can have other constructs, whatever the programming language provides.
I am trying to parse a text file and send its output to another file but I am having trouble conceptualizing how I am supposed to do this in awk.
The text file has a organization like so:
Name
Date
Status
Location (city, state, zip fields)
Where each of these is on a separate line in... (1 Reply)
Hello again everyone,
yes, I'm back again for more help! So I'm attempting to read two separate files and generate some XML code from that. My current code is:
BEGIN {
print "<?xml version=\"1.0\" encoding=\"utf-8\">"
print "<Export>"
}
{
x=1;
print "<section name=\"Query" NR "\">"... (5 Replies)
Folks - newbie bash coder here and I'd like to get your help to make the code below work. As you can see, I was trying to count the total number of lines with the 3rd value >= 15 in a file and wanted to make the threshold "15" configurable, but apparently the $THRESHOLD value was not populated... (3 Replies)
please let me know if the below code could be written efficiently inside single awk
case "$INP" in
ksh)
cat catalog | awk 'BEGIN {FS=",";} { print $2 } END {}'
;;
pset)
cat catalog | awk 'BEGIN {FS=",";} { print $3 } END {}'
;;
dml)
cat catalog | awk 'BEGIN {FS=",";} {... (2 Replies)
Deal Experts
I am working on a script to find a date which is 7 days older and follwoing is my approach
#!/bin/sh
Yr=`date +"%Y"`
Mn=`date +"%m"`
Md=28
Da=`date +"%d"`
echo $Yr
echo $Mn
echo $Da
var1=$Yr$Mn$Da
echo "before" $var1
if expr $Da > 7
then Da=`expr $Da - 7`... (3 Replies)
Hey all,
Can I put sed command inside the awk action ?? If not then can i do grep in the awk action ??
For ex:
awk '$1=="174" { ppid=($2) ; sed -n '/$ppid/p' tempfind.txt ; }' tempfind.txt
Assume: 174 is string.
Assume: tempfind.txt is used for awk and sed both.
tempfind.txt... (11 Replies)
Hello All, This work could be very easy for you guys. I would really appreciate help.
input file:
output file: (Desired)
What I am capable of doing:
Command: cat inputfile | awk -F\| '{print "num="$1" value="$2" digits="$3" name1="$4" file="$5" code="$6}' > outputfile
Result what I am... (5 Replies)
I have three arrays which hold three elements each.
I have a fourth array which contains the names of those three arrays.
I'm having difficulty creating a nested loop that can loop through each array and echo their values.
script
#!/bin/ksh
# array of locations (usa, london, australia)... (1 Reply)