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 and shell scripting languages 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 09:14 AM
how to read a file till it encounters a blank line adityam Shell Programming and Scripting 1 11-26-2007 02:15 AM
how to read a file till it encounters a blank line adityam Post Here to Contact Site Administrators and Moderators 0 11-26-2007 01:51 AM
Deleting First Two Characters On Each Line scotbuff Shell Programming and Scripting 5 12-16-2006 01:03 AM
how to get rid of blank line in a flat text file xfang Shell Programming and Scripting 11 05-28-2003 04:08 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-17-2005
rkumar28 rkumar28 is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 34
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
  #2 (permalink)  
Old 04-17-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511

Code:

 sed -e '/^$/{$d;N;}' file1


Code:
grep "^C" file1 | wc -l


Last edited by bhargav; 04-17-2005 at 04:19 AM..
  #3 (permalink)  
Old 04-17-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
The count process is better done as:


Code:
grep -c "C" file1

Cheers!
  #4 (permalink)  
Old 04-17-2005
rkumar28 rkumar28 is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 34
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
  #5 (permalink)  
Old 04-17-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
nawk -F'|'  '/^C/ { print length($1) }' 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 11:38 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