I don't think I was clear in my question: I wanted just the text in between the two phrases and that alone—nothing except that. If there is no match of the two phrases in one field then I want nothing to be returned, so if there is additional text before and after textA and/or textB, that text should not be there.
Okay, let me just give you guys the code I'm using and not dilly dally:
Working code to extract the local weather in my city.
Returns:
The code works beautifully as is (I added some of your code in there rdrtx to get rid of a dot! Grep clears a blank line at the end) when hard-coded, but as soon as I add the above variables it doesn't work as intended:
Unworking Code with variables added:
Returns nothing at all. How to make the awk understand and use the variables as in the working code?
Last edited by Don Cragun; 02-19-2018 at 03:20 PM..
Reason: Fix tags again. QUOTE->CODE, ICODE->CODE, add ICODE.
Your sample data included in your echo statement is nothing at all like the data you are looking for in the output from wget.
Maybe the following would come closer to doing what you want with a little less bother:
I can't test it on my laptop since it doesn't have a wget utility, but it should come close to doing what you want. If it doesn't, please show us the output the above wget command produces (in CODE tags), so we can see what the data you're trying to process really looks like.
Please also get into the habit of letting us know what operating system and shell you're using whenever you start a thread in this forum. The utilities (and the options they support) vary from system to system and shell features vary from shell to shell. Telling us details about your environment helps us provide you with suggestions that will work in your environment.
And, please use CODE tags (not ICODE and not QUOTE tags) for sample full-line and multi-line input, output, and code segments. Use ICODE tags when displaying partial-line sample input, output, and code segments in-line with other text.
I can't test it on my laptop since it doesn't have a wget utility, but it should come close to doing what you want. If it doesn't, please show us the output the above wget command produces (in CODE tags), so we can see what the data you're trying to process really looks like.
Please also get into the habit of letting us know what operating system and shell you're using whenever you start a thread in this forum. The utilities (and the options they support) vary from system to system and shell features vary from shell to shell. Telling us details about your environment helps us provide you with suggestions that will work in your environment.
And, please use CODE tags (not ICODE and not QUOTE tags) for sample full-line and multi-line input, output, and code segments. Use ICODE tags when displaying partial-line sample input, output, and code segments in-line with other text.
Thank you. And for me it does indeed work. I found that I didn't even need to use the NF==3 code as it was my original code that necessitated its use in the first place.
I'm on Debian, using bash, mksh, and sh, all of which work with this code... It seems I used the incorrect code tags—I see them now. I thought something was a trifle amiss.
RudiC,
This code worked, but for some reason it adds another line as mine had done. It's great to see some resolution on my own attempt!
Also, works. Looks like a lot more code to get the job done though. I've have to look at man pages and find out what it all does. This is my third day using awk.
Am looking to pass some Linux environment variables into AWK , can I simply use the -v option ?
awk -F: -v AHOME=$HOME '{ if
{rm AHOME/file.txt
a=2 } }'
config.txt
... (4 Replies)
Hi UNIX Members,
I've been tasked with performing the following:
Extract a block of data in column form
#This data changes each time, therefore automating future procedures
Please Note the following:
line = reading a line from a file_list that leads to the data
The filename is called... (16 Replies)
Hi All,
Iam trying to pass global shell variables and is not working
Main script is like below
CYEAR=`date +"%y"`
CFYEAR=`date +"%Y"`
CMONTH=`date +"%m"`
if
then
PMONTH=12
PYEAR=`expr $CYEAR - 1`
PFYEAR=`expr $CFYEAR - 1`
else
PMONTH=`expr... (6 Replies)
Using ksh to call a function which has awk script embedded.
It parses a long two element list file, filled with text numbers (I want column 2, beginning no sooner than line 45, that's the only known thing) . It's unknown where to start or end the data collection, dynamic variables will be used. ... (1 Reply)
Hi.
I need to parse file and assign some values to variables, right now i do like below
MYHOMEDIR=`awk '/Home/ {print $NF}' output.txt`
MYSHELL=`awk '/Shell/ {print $NF}' output.txt`
PRGRP=`awk '/Primary/ {print $NF}' output.txt`
SECGRP=`awk '/Second/ {print $NF}' output.txt`
In this... (10 Replies)
Hello,
I have two files File1 & File2.
File1
76 135
136 200
250 345
....
File2
1 24
1 35
1 36
1 72
....
I want to get all the values form File2 corresponding to the range in File 1 and feed it to a program. Is the code below right? Can I pass shell variables to awk in this... (2 Replies)
I am trying to pass the results from a variable gathered from awk, however when I echo the 'PARSE' and 'SUB', the response is blank. This is my command.
awk -F= '/Unit/''{ PARSE=substr($2,1,5) ; SUB=substr($2,1,1) }' inputfile.lst
Is this a kind of valid attempt or am I obligated to declare... (3 Replies)
Hi
I have a unix shell script with an awk statement. I would like to print some of the fields of an input file. However, I would like to print them dynamically, ie by passing the literal $1 $3 into the script to define the output.
I have tried the following:
variable1='$1'
awk... (2 Replies)