![]() |
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 |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| fetch substring from html code | scarfake | Shell Programming and Scripting | 2 | 05-29-2008 09:55 PM |
| How to fetch data from a text file in Unix | shikhakaul | Shell Programming and Scripting | 4 | 01-25-2008 11:20 AM |
| How To Fetch Time From Putside Source On Unix Platform? | pesty | UNIX for Advanced & Expert Users | 2 | 05-11-2007 07:06 AM |
| Fetch the field from file and add to new file. | maestrohero | Shell Programming and Scripting | 2 | 04-18-2007 09:00 PM |
| field delimiter with a space or more | uphamtn | UNIX for Dummies Questions & Answers | 3 | 05-15-2003 04:22 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Unix code to fetch the first field till space in a variable
Hi,
I want to get the value of the first field till space in a variable. e.g x=323 /test/personel/logs/File1 [After 3 space is there] I want to get the first field till space i.e 323 in another variable ,lets say y. echo $x|cut -d' ' -f1 gives 323 but when I'm trying y=`echo $x|cut -d' ' -f1 its giving error. Please help. |
|
||||
|
Hi! to be sure, since your value has a space in between them, enclosed them with a double quotes, like this:
Code:
x="323 /test/personel/logs/File1" Code:
y=`echo $x|cut -d' ' -f1` |
|
||||
|
It's both safer and more efficient to use the shell's built-in variable substitution syntax.
Code:
y=${x% *}
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|