Register
It is currently Wed Dec 17, 2014 2:09 pm

Use data from file in script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Thu Apr 08, 2010 7:21 am   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
In a bash script I need to get the first line of data from a file and add it to the end of a URL in the same script

I think using

Code:
awk 'NR==1' file


Is probably the best way but how do I run this within a script? I need something like

output=awk 'NR==1' process

curl http://www.bashscripts.org/$output

or

From an rss feed I get a url which I then need to parse.

Which ever is the easiest


Top
 Profile  
 PostPosted: Fri Apr 09, 2010 1:50 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
if it's the first line you're after you can always use head.

Code:
curl http://www.bashscripts.org/$output | head -n1


Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Fri Apr 09, 2010 2:50 am   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
Thanks for that i'm almost there

Basically via http request i'm doing curl domain.com|grep (numbers 0-9) this returns random numbers ie 1234

The next line ie need to do curl domain1.com/1234

the second domain is always the same, hope this makes sense ha.

I'm sure there's an easier way to do this as currently it's writing the output to a file then having url inserted into it and then running curl which seems a bit long winded.


Top
 Profile  
 PostPosted: Fri Apr 09, 2010 3:11 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
maybe...
Code:
curl otherdomain.com/$(curl domain.com | grep '[[:digit:]]' | head -n1)


must admit I rarely use curl, being a wget man. From what I've heard curl is better though :)


Top
 Profile  
 PostPosted: Fri Apr 09, 2010 8:47 am   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
Alas i'm quite new to curl as well as you can probably tell.

The code isn't working as it appears the output isn't being added to the end of otherdomain.com, just executing the second part does return the number ok.


Top
 Profile  
 PostPosted: Mon Apr 12, 2010 6:28 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
if you try;

Code:
echo "##$(curl domain.com | grep '[[:digit:]]' | head -n1)##"


this should check for any rogue characters, for example if the statement retuens;
Code:
## 345
##


Then we can see that the output includes a proceeding space and a trailing newline. The newline would not matter but the space sure would. It's rather difficult to suggest a fix when we have no real info about how it failed as we cannot test it ourselves :)


Top
 Profile  
 PostPosted: Sat Apr 24, 2010 1:31 pm   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
Just started on this again thanks for the code, just the trick :)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP