Solved

wc -l on unix file

Posted on 2006-06-09
12
4,793 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

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!

Question has a verified solution.

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

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

735 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