![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Extract string between <> | rakeshou | Shell Programming and Scripting | 14 | 11-21-2007 01:10 PM |
| Extract numbers from a string and store in variables | davewg | Shell Programming and Scripting | 6 | 11-14-2007 05:22 AM |
| Extract String | sehgalniraj | UNIX for Dummies Questions & Answers | 1 | 09-25-2006 12:35 PM |
| Extract String | bestbuyernc | Shell Programming and Scripting | 5 | 11-14-2005 03:42 PM |
| How to extract a portion of a string from the whole string | ds_sastry | UNIX for Dummies Questions & Answers | 2 | 09-29-2001 10:40 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
extract from string variable into new variables
I have a variable which consists of a string like this:
001 aaabc 44 a bbb12 How do I extract each substring, delimited by the spaces, into new variables - one for each substring? eg var1 will be 001, var2 will be aaabc, var3 will be 44, var4 will be a, etc? I've come up with this: var1=$(echo $string | awk 'NF=1') ; var2=$(echo $string | awk 'NF=2') ; var3=$(echo $string | awk 'NF=3') but var2 = NF1 and 2, var3 = NF 1,2,3 etc It also seems a bit long winded and impractical for operating on a lengthy string. Last edited by Sniper Pixie; 03-02-2006 at 02:58 PM.. |
|
|||||
|
See previous answer.
At the bash prompt... Code:
$ var="001 aaabc 44 a bbb12" $ set $var $ echo $1 001 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|