The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regardign strtok() output directing to 2-D string array SankarV High Level Programming 3 04-28-2008 06:48 AM
bash:awk output into an array phamp008 Shell Programming and Scripting 2 03-16-2008 02:14 AM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 05:42 AM
output of an array ragha81 Shell Programming and Scripting 3 03-22-2007 01:30 PM
formating array file output using perl seismic_willy Shell Programming and Scripting 4 03-21-2007 11:23 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 12-19-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
depending on the shell you are using
Code:
# set -- $array 
# echo $6
or else , if you just want to get the 6th field, you can do it inside awk. If you list4.txt is just one column, your 6th item would be NR==6
Code:
# result=`awk 'NR==6{print}' list4.txt`
# echo "this is my 6th item : $result"
Reply With Quote
Forum Sponsor
  #9  
Old 12-19-2007
Registered User
 

Join Date: Oct 2007
Posts: 43
Hi,

My shell is tcsh,

What I am looking for is,

array=`awk '{print $1}' /users/jon/list4.txt`
array2=`awk '{print $1}' /users/jon/list5.txt`

If value in array[] Not equal array2[]
then
echo value of arra[] >> ~/noval.txt

can I do this?

Thanks

Amit
Reply With Quote
  #10  
Old 12-19-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Code:
# awk '{print $1}' /users/jon/list4.txt > 1.txt
# awk '{print $1}' /users/jon/list5.txt > 2.txt
# diff 1.txt 2.txt
# echo $? #use this to check whether the 2 files are different.
I leave the rest of the code to you. before you diff the 2 files, use sort to sort the items , or you can sort them by piping the output of awk to sort.
Reply With Quote
  #11  
Old 12-19-2007
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
While I agree with the method ghostdog74 proposes, the user specifically asked for a tcsh solution. Here is one that should work provided the files are small.

Code:
#!/bin/tcsh

set a=`awk '{print $1}' file1`
echo $a
echo "$a[2]"
echo "$#a"

set b=`awk '{print $1}' file2`
echo $b
echo "$b[2]"
echo "$#b"

if ($#a == $#b) then
   echo "number of lines match"
else
   echo "number of lines do not match"
endif

if ("$a" == "$b") then
   echo "files match"
else
   echo "files do not match"
endif
Reply With Quote
  #12  
Old 12-20-2007
Registered User
 

Join Date: Oct 2007
Posts: 43
Quote:
Originally Posted by ghostdog74 View Post
Code:
# awk '{print $1}' /users/jon/list4.txt > 1.txt
# awk '{print $1}' /users/jon/list5.txt > 2.txt
# diff 1.txt 2.txt
# echo $? #use this to check whether the 2 files are different.
I leave the rest of the code to you. before you diff the 2 files, use sort to sort the items , or you can sort them by piping the output of awk to sort.
Hi,

when we do line by line compare for file1 and file2 , how do I extract the value in file1 which did not match that in file2.

Will it work even if sort, because there could be some order in file2.

Let me know

Thanks

Amit
Amit
Reply With Quote
  #13  
Old 12-20-2007
Registered User
 

Join Date: Oct 2007
Posts: 43
Quote:
Originally Posted by fpmurphy View Post
While I agree with the method ghostdog74 proposes, the user specifically asked for a tcsh solution. Here is one that should work provided the files are small.

Code:
#!/bin/tcsh

set a=`awk '{print $1}' file1`
echo $a
echo "$a[2]"
echo "$#a"

set b=`awk '{print $1}' file2`
echo $b
echo "$b[2]"
echo "$#b"

if ($#a == $#b) then
   echo "number of lines match"
else
   echo "number of lines do not match"
endif

if ("$a" == "$b") then
   echo "files match"
else
   echo "files do not match"
endif
Hi murphy,

how do I get the line which did not match? from your script

Pls help

Amit
Reply With Quote
  #14  
Old 12-20-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by amitrajvarma View Post
Hi,

when we do line by line compare for file1 and file2 , how do I extract the value in file1 which did not match that in file2.

Will it work even if sort, because there could be some order in file2.

Let me know

Thanks

Amit
Amit
first, sort the 2 files. man sort for more information.
then, use comm to compare them. man comm for more information
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0