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
Solved

wc -l on unix file

Posted on 2006-06-09
12
4,792 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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 500 total points
ID: 16872766
newcount="$rowcount" | cut -f1 -d' '
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

790 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