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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to count number of delimiters in a file name ayanbiswas UNIX for Dummies Questions & Answers 4 07-02-2008 05:57 AM
Adding a columnfrom a specifit line number to a specific line number Ezy Shell Programming and Scripting 2 05-12-2008 08:29 AM
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 10:19 AM
awk script to find the number of files uni_ajay_r Shell Programming and Scripting 4 10-31-2006 06:58 PM
Unix Script with line number at beginning of each line. mascorro Shell Programming and Scripting 5 06-19-2006 04:34 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 09-27-2008
poornimajayan poornimajayan is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 2
Script to find the number of tab delimiters in a line

Hi,
I need to find the number of tab delimiters in the first line of a file.So using
word=`head -1 files.txt`
I have extracted the first line of file into a variable word.It has 20 tab delimted columns.So can anyone help me in finding the number of delimiters?
I am using csh and I am a beginner.I feel like printf and awk are not working. Not sure
Also I would like to know how can I call this shell using Autosys Jobs by giving the file name as a parameter.Do I need to write the script something like a function?
As of now I am reading from the user as echoing and reading the filename.But how I will implement in Autosys?
Please help.
Thanks,
Poornima
  #2 (permalink)  
Old 09-29-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,753
Few people here are good with csh, me included. There are good reasons to avoid it.
However, you can get the answer with awk. Try gawk or nawk if you have them.
Code:
head -1 file | awk -F'*' '{print $NF -1 }'
* where * -- the tab key

Last edited by jim mcnamara; 09-29-2008 at 10:36 AM.. Reason: gotgot to make FS == a tab
  #3 (permalink)  
Old 09-29-2008
rajendra44 rajendra44 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 10
Hi u can try this


This will give the count of Tab or delimeter
1. head -1 file | awk -F'<delimiter>' '{print NF -1}'

2. head -1 file | awk '{print NF -1}' as defult it takes space and tabs as delimeter

Thanks
  #4 (permalink)  
Old 09-29-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink Here is another approach

Code:
> cat infile2
joe     blue    1       15      99
harry   orange  5       13      2
steve   red     57      99      98
> head -1 infile2 | tr -d "\n" | tr "\t" "\n" | wc -l
4
Explained:
head -1 takes the top line
tr -d "\n" gets rid of extra line feeds
tr "\t" "n" converts tabs to line feeds
wc -l counts the number of lines (that line feeds caused)
  #5 (permalink)  
Old 09-29-2008
poornimajayan poornimajayan is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 2
Thanks a lot gurus.
I used Joeyg's approach and it worked.
When I tried Jim's solution head -1 file | awk -F'|' '{print $NF -1 }', it is giving me -1.Just of curiosity..What does that mean?
Anyway thanks.It helped me..
  #6 (permalink)  
Old 09-29-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,753
my bad: wrong field separator - I edited the post.
Closed Thread

Bookmarks

Tags
autosys

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 02: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