Count tab in a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count tab in a line
# 1  
Old 06-15-2010
Count tab in a line

Hi,

How to count number of tabs in a line
# 2  
Old 06-15-2010
Try this:
Code:
echo "$line" | awk '{print gsub(/\t/,"")}'

or
Code:
awk '{print gsub(/\t/,"")}' infile


Last edited by Scrutinizer; 06-15-2010 at 04:26 AM..
# 3  
Old 06-15-2010
Code:
# cat infile
sasasa  dwedwdw dewedwed        dwdqwd  ddwed   ddfwe

Code:
# od -c infile | grep -o "\t" | wc -l
6

# 4  
Old 06-15-2010
Hi ygemici, don't you mean:
Code:
grep -o "\t" infile | wc -l

# 5  
Old 06-15-2010
Quote:
Originally Posted by Scrutinizer
Hi ygemici, don't you mean:
Code:
grep -o "\t" infile | wc -l

Actually I dont mean this..because we dont look the invisible chars in normal text with grep..

Code:
sed 's/\t/--TABHERE--/g' infile
sasasa--TABHERE--dwedwdw--TABHERE--dewedwed--TABHERE--dwdqwd--TABHERE--ddwed--TABHERE--ddfwe--TABHERE--

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count the pipes "|" in line and delete line if count greter then number.

Hello, I have been working on Awk/sed one liner which counts the number of occurrences of '|' in pipe separated lines of file and delete the line from files if count exceeds "17". i.e need to get records having exact 17 pipe separated fields(no more or less) currently i have below : awk... (1 Reply)
Discussion started by: ketanraut
1 Replies

2. Shell Programming and Scripting

Removing tab spaces at the end of each line

I have a file which contains the data lines like below.I want to remove the tab spaces at the end of each line.I have tried with the command sed 's/\+$//' file.but it does not work.Can anyone help me on this? 15022 15022 15022 15022 15022 15022 15023 15023 15023 15023 15023 ... (16 Replies)
Discussion started by: am24
16 Replies

3. Shell Programming and Scripting

Compare file1 header count with file2 line count

What I'm trying to accomplish. I receive a Header and Detail file for daily processing. The detail file comes first which holds data, the header is a receipt of the detail file and has the detail files record count. Before processing the detail file I would like to put a wrapper around another... (4 Replies)
Discussion started by: pone2332
4 Replies

4. Shell Programming and Scripting

Adding tab/new line at the end of each line of a file

Hello Everyone, I need a help from experts of this community regarding one of the issue that I am facing with shell scripting. My requirement is to append char's at the end of each line of a file. The char that will be appended is variable and will be passed through command line. The... (20 Replies)
Discussion started by: Sourav Das
20 Replies

5. Shell Programming and Scripting

Shell script to count number of ~ from each line and compare with next line

Hi, I have created one shell script in which it will count number of "~" tilda charactors from each line of the file.But the problem is that i need to count each line count individually, that means. if line one contains 14 "~"s and line two contains 15 "~"s then it should give an error msg.each... (3 Replies)
Discussion started by: Ganesh Khandare
3 Replies

6. Shell Programming and Scripting

Read and copy xml line by line and preserve tab?

I'm trying to read an xml file and copy it line by line to another file and want to preserve the tabs. What i'm trying to do is if I get to a certain line in the xml, I'm going to check to see if the next line is specifically what I want. If it's not, then I want to insert a single line of text... (4 Replies)
Discussion started by: DeuceLee
4 Replies

7. Shell Programming and Scripting

how to replace new line ( \n ) with space or Tab in Sed

Hi, how to replace new line with tab in sed ... i used sed -e 's/\n/\t/g' <filename > but its not working (1 Reply)
Discussion started by: mail2sant
1 Replies

8. Shell Programming and Scripting

convert new line to tab

hey i m newbie i dont know whether this is happining in my terminal or is there any reason behind this here it is when i do 1.) sed -n 's/\t/\n/gp' space > enter #where space is tab seperated file it works fine it give me a outupt that all tab seperated convert into column but when i... (3 Replies)
Discussion started by: narang.mohit
3 Replies

9. UNIX for Dummies Questions & Answers

tab every new line

Hi ,need script to tab every new line of sorted output Thanx (2 Replies)
Discussion started by: chassis
2 Replies

10. Shell Programming and Scripting

using tab to finish command line parameter

Anyone know how to set it up so that when at command line in unix (specifically solaris 2.5.1), and you hit the tab it will finish the command with the nearest file that matches? AND how to set it up so using up and down arrows access your previous commands? Thanks for all the help here, i've had... (3 Replies)
Discussion started by: kymberm
3 Replies
Login or Register to Ask a Question