The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Strip one line from 2 blank lines in a file tipsy Shell Programming and Scripting 6 06-23-2008 05:14 AM
how to read a file till it encounters a blank line adityam Shell Programming and Scripting 1 11-25-2007 10:15 PM
how to read a file till it encounters a blank line adityam Post Here to Contact Site Administrators and Moderators 0 11-25-2007 09:51 PM
Deleting First Two Characters On Each Line scotbuff Shell Programming and Scripting 5 12-15-2006 09:03 PM
how to get rid of blank line in a flat text file xfang Shell Programming and Scripting 11 05-28-2003 12:08 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-16-2005
Registered User
 

Join Date: Apr 2004
Posts: 31
Stumble this Post!
Deleting the blank line in a file and counting the characters....

Hi,
I am trying to do two things in my script. I will really appreciate any help in this regards.
  • Is there a way to delete a last line from a pipe delimited flat file if the last line is blank. If the line is not blank then do nothing.....
  • Is there a way to count a word that are starting with "C" in the first column of a pipe delimited flate file.

Thanks a lot for help and time in this regards.

Raj
__________________
Thanks
Raj
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-17-2005
bhargav's Avatar
Registered User
 

Join Date: Sep 2004
Location: USA
Posts: 511
Stumble this Post!
Code:
 sed -e '/^$/{$d;N;}' file1
Code:
grep "^C" file1 | wc -l

Last edited by bhargav; 04-17-2005 at 12:19 AM.
Reply With Quote
  #3 (permalink)  
Old 04-17-2005
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,325
Stumble this Post!
The count process is better done as:

Code:
grep -c "C" file1
Cheers!
Reply With Quote
  #4 (permalink)  
Old 04-17-2005
Registered User
 

Join Date: Apr 2004
Posts: 31
Stumble this Post!
Deleting the blank line in a file and counting the characters....

Thanks for replying on this.

I am sorry I potrayed the second part incorrectly. I need to count the letters for the words that starts with "C" in the first column in a pipe delimited file.

Something like:

C1213456| ---->this has 8 characters
C123|---->this has 4 characters

I have to pass this number to a variable.....

Thanks again for the time and help....


Raj
__________________
Thanks
Raj
Reply With Quote
  #5 (permalink)  
Old 04-17-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
Stumble this Post!
Code:
nawk -F'|'  '/^C/ { print length($1) }' file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0