![]() |
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 |
| How to compare a field value of a same column? | gobinath | Shell Programming and Scripting | 6 | 05-06-2009 01:39 AM |
| Compare 2 files through multiple fields | newinawk | Shell Programming and Scripting | 4 | 06-12-2008 04:34 PM |
| how to read the column and print the values under that column | gemini106 | Shell Programming and Scripting | 6 | 03-28-2008 07:05 AM |
| awk compare column between 2 files | phamp008 | Shell Programming and Scripting | 3 | 01-18-2008 12:24 AM |
| Compare two arrays in sh or compare two fields | rijeshpp | Shell Programming and Scripting | 0 | 10-31-2007 02:47 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to read and compare multiple fields in a column at the same time
Hi,
Currently I am coding up a nasty way of reading file input using *cat* rather than *read*. My text input looks like TextA 100 TextB 110 TextC 120 Currently I am using cat |while read line to read the first column and second column fields. cat foo.txt|while read line do myfirstcol=`echo "${LINE}"| awk '{print $1}'` mysecondcol=`echo "${LINE}"|awk '{print $2}'` However, I would like to implement more intelligent code where there can be more than one cases in the second field. TextA 100,101 TextB 110,143,155,160 TextC 120,200 and from reading the possiblities of second column, i wanted to choose the smallest grep value. e.g mysecondcol=`echo "${LINE}"|awk '{print $2}'` #return the position grep -n mysecondcol$ fileA.txt Basically if by grabbing 100 return position 30 from grep, and grabbing 101 return position 1 from grep., it would choose the smallest which is 101 (since it return 1). I am not too sure how can i implement the above logic by using *read data* Please advise. Thanks. |
|
||||
|
Code:
while read record
do
set -A recarray $( echo "$record" | tr -s ',' ' ')
# at this point you now have an array - ${recarray[0]} is column 1, the rest of the
# elements came from column 2
done < inputfile
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|