?
Solved

wc -l on unix file

Posted on 2006-06-09
12
Medium Priority
?
4,806 Views
Last Modified: 2012-05-05
I have a unix script that I am check a data file record count. When I do the following I get the count and the file name assign to the variable. How can I get just the record count?

 TOTAL_RECORDS=`wc -l ${staging_dir}${curr_action_file}`

Thanks
0
Comment
Question by:TClevel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
12 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16870008
wc -l ${staging_dir}${curr_action_file}
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16870009
... but maybe I am missing something
0
 

Author Comment

by:TClevel
ID: 16870053
when I do wc -l ${staging_dir}${curr_action_file}
I get this 503883 /opt/envproc/nationwide/unprocessed/NWPOL20060609_d.TXT
I only what 503883

I just what the count in the variable not the file name
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:NickUpson
ID: 16870101
wc -l ${staging_dir}${curr_action_file} | cut -1
0
 

Author Comment

by:TClevel
ID: 16870259
I input the following and I get the error below

rowcount=`wc -l ${record_count_datafile}${FILE_FROM_NATIONWIDE} | cut -1`

cut: illegal option -- 1
usage: cut -b list [-n] [filename ...]
       cut -c list [filename ...]
       cut -f list [-d delim] [-s] [filename]
0
 
LVL 19

Expert Comment

by:NickUpson
ID: 16870341
sorry, that is what comes of trying to type faster than brain

the end part should be      | cut -f1
0
 

Author Comment

by:TClevel
ID: 16870532
I am still getting
503883 /opt/envproc/nationwide/unprocessed/NWPOL20060609_d.TXT
when I use

rowcount=`wc -l ${record_count_datafile}${FILE_FROM_NATIONWIDE} | cut -f1`
echo $rowcount

Any other suggestion
0
 
LVL 19

Expert Comment

by:NickUpson
ID: 16870640
this one I tested

| cut -f1 -d' '
0
 

Author Comment

by:TClevel
ID: 16870786
Now I get nothing when i echo $rowcount
0
 
LVL 19

Expert Comment

by:NickUpson
ID: 16870852
[root@ueserv2 root]# rowcount=`wc -l /etc/passwd`
[root@ueserv2 root]# echo $rowcount | cut -f1 -d' '
35
0
 

Author Comment

by:TClevel
ID: 16871085
Yes it will display the count without the file name when I use echo but when I try to assign it to a variable and then display it I don't get anything. I need to assign the result to a variable to use later in the script.

NW2HOME=/opt/envproc/nationwide/
record_count_datafile=${NW2HOME}unprocessed/
newcount=$rowcount | cut -f1 -d' '

echo $newcount

I get nothing from the echo
0
 
LVL 19

Accepted Solution

by:
NickUpson earned 2000 total points
ID: 16872766
newcount="$rowcount" | cut -f1 -d' '
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question