Sponsored Content
Top Forums Shell Programming and Scripting Sending awk variables into curl in a bash script Post 302955377 by Aia on Wednesday 16th of September 2015 10:47:06 PM
Old 09-16-2015
Quote:
Originally Posted by phaethon
[...]
but it seems that the variables are not evolving gradually all together but separately
Code:
yr=`awk '{$1=substr($1, 6, 2)}1'  file1`

yr will not hold just one year, but every year for each line in file1. The same for each of your variables mo, da, ho and mi. Nonetheless, the characters extracted are off: substr($1, 6, 2) doesn't return the representation of a year.
Code:
$ awk '{$1=substr($1, 6, 2)}1' file1 
11
21
41
01

This will do:
Code:
$ awk '{$1=substr($1, 1, 4)}1' file1
2012
2012
2013
2014

Perhaps, try:
Code:
while read d; do
    yr=${d:0:4}
    mo=${d:4:2}
    da=${d:6:2}
    ho=${d:8:2}
    mi=${d:10:2}
    curl -L http://webpage/${yr}/${mo}/track${yr}${mo}${da}${ho}${mi}_infos.html
    # if yr is supposed to be yyyy
    # curl -L http://webpage/${yr}/${mo}/track${d}_infos.html
    
done < file1

If yr is supposed to be represented with only the last two digits, replace yr=${d:0:4} to yr=${d:2:2}

Of course, the whole process can be reduced to:

Code:
while read d; do
    #curl -L http://webpage/${d:0:4}/${d:4:2}/track${d}_infos.html
    # or
    #curl -L http://webpage/${d:2:2}/${d:4:2}/track${d:2}_infos.html
done < file1


Last edited by Aia; 09-17-2015 at 12:44 AM.. Reason: Add an alternative
This User Gave Thanks to Aia For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using sed on bash variables (or maybe awk?)

Hi all- I've been fooling with this for a few days, but I'm rather new at this... I have a bash variable containing a long string of various characters, for instance: JUNK=this that the other xyz 1234 56 789 I don't know what "xyz" actually is, but I know that: START=he other and ... (2 Replies)
Discussion started by: rev66
2 Replies

2. Shell Programming and Scripting

Bash script idea using cUrl -- possible?

I have an alias already in my .bash_profile to download files using cUrl's -o (output to file, user provides the file name) option. I find I'm using it quite a bit, so I wanted to write a script to run "curl -o", taking the necessary inputs - file name and URL from which to download - and then... (3 Replies)
Discussion started by: SilversleevesX
3 Replies

3. Shell Programming and Scripting

using awk compare two variables in bash

ok this is probably going to turn out to be something really stupid but i've tried to use the following command in a script but the output is just a blank screen and i have to use Ctrl c to exit it. awk 'BEGIN {printf "%.2f\n", '${bashArray}'>='$Variable' {print '${bashArray}'}}' the command... (2 Replies)
Discussion started by: zagreus360
2 Replies

4. UNIX for Dummies Questions & Answers

curl - sending headers, no-cache

Hello, I have question about curl - how can I disable caching on server side? I actually am not on unix/linux but I use win32gnu curl. I look for some good web- manual and I would like to find some good site which describes how looks headers of various Browsers (Safari, Opera). I have FF and... (0 Replies)
Discussion started by: webhope
0 Replies

5. Shell Programming and Scripting

Bash for loop with awk and variables

I'm relatively new to bash scripting and am trying to use awk inside a bash for loop but am having a problem with the variables. for i in $(seq 30 5 60) do # Define variables up and down in AWK eval $(awk 'BEGIN{ print "up=$((i+1))"}' < /dev/null) eval $(awk 'BEGIN{ print... (2 Replies)
Discussion started by: lily-anne
2 Replies

6. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

7. Shell Programming and Scripting

Curl/http 503 error with bash script

I am trying to use REST API and curl in a bash script to generate a http report. The curl command at the end of the script should generate a html file but instead I get an error "HTTP/1.1 503 Service Unavailable". This is the script #!/bin/bash export... (7 Replies)
Discussion started by: kieranfoley
7 Replies

8. Shell Programming and Scripting

Using curl in bash script

Hello. I have pick up a script from internet to track errors from curl command. #!/bin/bash # URL_TO_TEST="http://www.xxxxxx.yyy" MY_VAR=curl_init("$URL_TO_TEST") ; curl_setopt($MY_VAR, CURLOPT_HEADER, 1); curl_setopt($MY_VAR, CURLOPT_RETURNTRANSFER, 1); curl_setopt($MY_VAR,... (2 Replies)
Discussion started by: jcdole
2 Replies

9. Shell Programming and Scripting

Curl , download file with user:pass in bash script

Hello, My question is about curl command. (ubuntu14.04) In terminal, I am able to download my mainfile with: curl -u user1:pass1 http://11.22.33.44/******* When I convert it into bash script like this: #!/bin/bash cd /root/scripts computer_ip=11.22.33.44 curl -u $1:$2... (8 Replies)
Discussion started by: baris35
8 Replies

10. Shell Programming and Scripting

Curl not accepting spaces in script via variables

Hi All, I'm trying to run a script which issues rest commands via curl to an endpoint. If I put spaces in fields via something like insomnia, it works, but when I try from an input file, it's failing with a json error. while IFS=, read mname oname <------ my input file... (10 Replies)
Discussion started by: say170
10 Replies
All times are GMT -4. The time now is 02:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy