The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to get a file name & record count of csv file sirik UNIX for Dummies Questions & Answers 2 03-06-2008 02:55 PM
How count number of fields in a record sureshg_sampat Shell Programming and Scripting 5 01-07-2008 06:30 AM
splitting a record and adding a record to a file rsolap Shell Programming and Scripting 1 08-13-2007 01:58 PM
Need help with Isql record count johnu122 Shell Programming and Scripting 4 11-18-2006 12:31 PM
How to count the record count in an EBCDIC file. oracle8 UNIX for Dummies Questions & Answers 1 07-26-2006 07:22 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-11-2007
dr46014 dr46014 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 94
record count

i have a file named file_names.dat where there are several files along with their path.
exp:
/data1/dir1/CTA_ACD_20071208.dat
/data1/dir1/CTA_DFG_20071208.dat

i want to write a script which will create a csv file with the name of the file and record count of that file

the output file should look like
/data1/dir1/CTA_ACD_20071208.dat,2500
/data1/dir1/CTA_DFG_20071208.dat,5633

please help me writing the script
  #2 (permalink)  
Old 12-11-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
what is a 'record'?
what's the "structure" of the files?
  #3 (permalink)  
Old 12-11-2007
dr46014 dr46014 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 94
each record is terminated by a newline character \n
wc -l /data1/dir1/CTA_ACD_20071208.dat
  #4 (permalink)  
Old 12-11-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
#!/bin/ksh

(while read file
do
  echo "${file},$(wc -l < ${file}" 
done < 'file_names.dat') > 'file_name.csv'
  #5 (permalink)  
Old 12-11-2007
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Code:
awk '
{
  "wc -l <"$0 | getline cnt
  print cnt,$0
}' file
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 03:22 PM.


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