LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 10-09-2011, 12:12 PM   #16
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44

Brilliant! we're on the exact same page!

Now I implemented your suggestions in my script but I am not entirely sure of the logic and syntax of the first string extractor...

Code:
${x%% *}
I understand the whitespace in the command above is the delimiter. I tried substituting the space for a plus sign, and added a + sign somewhere in the string to search, and I got everything from the start top the + sign...

But if I wanted to extract the 3rd string, how would you do this? Using whitespaces as delimiters would work. Lets say for

Code:
StringA 123 4567 4568 RandomStringA StringB RandomStringB
I want to return what is between the 4th & 5th space, i.e. the "RandomStringA"

Thanks, I appreciate your mentoring

Last edited by lpallard; 10-09-2011 at 12:16 PM.
 
Old 10-09-2011, 12:22 PM   #17
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44
I may have found something... Reading the tutorials on awk, I found this:

Code:
echo $string | awk '{split($position-of-the-delimiter,a,"delimiter");print a[1]}'
so if I want to return the 5th string (separated by spaces) I'd use:

Code:
echo $string | awk '{split($5,a," ");print a[1]}'
which returns

Code:
RandomStringA
Is there a better way to do that?
 
Old 10-09-2011, 12:28 PM   #18
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,627

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Code:
echo $string | awk '{print $5}'
Your code was floored as it would grab the fifth field and split on spaces of which there is none and just return the full string anyway.

I am curious ... how is any of what we are doing now related to the original question of splitting html code to be used by curl??
 
1 members found this post helpful.
Old 10-09-2011, 01:07 PM   #19
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44
Quote:
I am curious ... how is any of what we are doing now related to the original question of splitting html code to be used by curl??
not related at all. I thought keeping the same type of questions in the same thread so I can collate the learning better...

With your help, I think I am done!

I just tried with a bunch of test directories and files, works pretty well!

Thanks a lot!
 
Old 10-09-2011, 07:35 PM   #20
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,627

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Helping is not so much the problem but if someone else tries to search for your second set of solutions it may be harder to find as there is no specific topic

General rule of thumb here is that if you want to ask an alternate question which diverges enough from the original then it is probably best to close one question and ask
another.

Glad you got to where you were going though
 
Old 10-09-2011, 07:54 PM   #21
lpallard
Member
 
Registered: Nov 2008
Location: Milky Way
Distribution: Slackware (various releases)
Posts: 970

Original Poster
Rep: Reputation: 44
Quote:
General rule of thumb here is that if you want to ask an alternate question which diverges enough from the original then it is probably best to close one question and ask
another.
Yeah I had the feeling it would be better... "Should have"...

Sorry about that!
 
Old 10-09-2011, 09:01 PM   #22
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,627

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
nah ... no biggee
 
  


Reply

Tags
awk


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Searching and replacing strings in a file with strings in other files xndd Linux - Newbie 16 07-29-2010 03:40 PM
Bash - Searching strings for array elements... Phier Programming 18 05-09-2010 05:37 AM
How to parse strings in bash script crimson08 Linux - Newbie 17 05-11-2009 12:29 PM
Want to compare strings in bash script IsharaComix Programming 6 10-28-2008 09:49 PM
bash script help (arrays and strings from files) nkoplm Programming 14 12-02-2005 10:50 AM


All times are GMT -5. The time now is 10:48 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration