![]() |
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 |
| split string using separetor | rinku | Shell Programming and Scripting | 10 | 06-16-2009 02:01 PM |
| [KSH] Split string into array | piooooter | Shell Programming and Scripting | 3 | 09-01-2007 12:22 PM |
| KSH split string into variables | drd_2b | Shell Programming and Scripting | 5 | 04-23-2006 07:07 PM |
| split string help | senthilk615 | Shell Programming and Scripting | 4 | 03-27-2006 06:43 PM |
| split a file at a specified string | jpl35 | Shell Programming and Scripting | 6 | 07-04-2002 11:41 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
split a string
Hi
I have a script that loops though lines of a file and reads each line in to a variable ($LINE). I want to look at the line and split it into it's constituent parts. e.g. a line might be "This is a string" I want to then have variables set to each element thus: A=This B=is C=a D=string I'm guessing it should be simple but cannot figure it out. |
|
||||
|
Code:
while read a b c d e f
do
echo "a = $a"
echo "b = $b"
echo "c = $c"
echo "d = $d"
echo "e = $e"
echo "f = $f"
done < myfile
|
|
||||
|
whether you need awk depends on what you want to after the assignment. If you want the variable outside the awk statement maybe using awk may not be very helpful. But, in situations , where you require processing data, this is seldom the case---you can do everything you want inside awk.
awk '{for(i=1;i<=NF;++i) { print "Field " i " is "$i} print ""}' file_name for example prints out all fields, in all lines in the file |
| Sponsored Links | ||
|
|