The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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
Passing variables to sed jfisch Shell Programming and Scripting 3 03-07-2005 07:25 AM
Passing awk Variables gozer13 Shell Programming and Scripting 3 01-04-2005 04:32 PM
Passing Variables to Awk Bab00shka Shell Programming and Scripting 2 10-05-2004 08:18 AM
passing variables sounder123 Shell Programming and Scripting 1 06-10-2004 10:19 AM
Passing Variables to AWK AreaMan Shell Programming and Scripting 5 01-28-2002 06:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-13-2005
keladar keladar is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 4
Passing specific fields from files as variables

Hi all,

I have a question regarding passing specific fields from files to shell scripts as variables. I have 2 files, I want to compare the record counts of these files in a shell script. Thus far I have done:

wc -l file1 > file1test

yields: 73 filename

wc -l file2 > file2test
yields: 73 filename

What I want to do is take the 73 field from each file and store them in separate variables, then use those variables in a conditional statement.

Any help would be greatly appreciated.

Last edited by keladar; 04-14-2005 at 01:04 AM..
  #2 (permalink)  
Old 04-13-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Quote:
Originally Posted by keladar
I have a question regarding passing specific fields from files to shell scripts as variables. I have 2 files, I want to compare the record counts of these files in a shell script. Thus far I have done:

wc -l file1 > file1test

yields: 73 filename

wc -l file2 > file2test
yields: 73 filename

What I want to do is take the 73 field from each file and store them in separate variables, they use those variables in a conditional statement.


Code:
VARIABLE_1=`wc -l file1 | awk -F\  '{print $1}'`
VARIABLE_2=`wc -l file2 | awk -F\  '{print $1}'`

  #3 (permalink)  
Old 04-13-2005
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
  
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 637
or ...

Code:
VARIABLE_1=`awk 'END {print NR}' file1`
VARIABLE_2=`awk 'END {print NR}' file2`

  #4 (permalink)  
Old 04-13-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Quote:
Originally Posted by Just Ice
or ...

Code:
VARIABLE_1=`awk 'END {print NR}' file1`
VARIABLE_2=`awk 'END {print NR}' file2`
Now you made me wonder if one was faster.

Code:
$ time awk 'END {print NR}' bigfile
1314268

real    1m50.36s
user    1m42.52s
sys     0m5.35s

$ time wc -l bigfile | awk -F\  '{print $1}'
1314268

real    0m18.67s
user    0m13.19s
sys     0m4.33s

  #5 (permalink)  
Old 04-13-2005
keladar keladar is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 4
All,

Thanks alot, this worked well. I appreciate the help!!!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0