Solved

wc -l on unix file

Posted on 2006-06-09
12
4,795 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…

738 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