Number of Tabs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Number of Tabs
# 1  
Old 09-21-2010
Number of Tabs

hi,

I have a text and values are seperated by tab. each line has different tabs. I am getting values and writing values in a specific format using:

Code:
awk 'NR>1 {print "First value: "$1" Second:"$2" Third: "$3 } /home/gcsw/readtext.txt > /home/gcsw/writeresults.txt

but how can i determine the total number of values in a line? because each line has different number of tabs?

Last edited by gc_sw; 09-21-2010 at 07:35 AM..
# 2  
Old 09-21-2010
NF can tell you the number of column on each line.

You need provide some samples to us.
# 3  
Old 09-21-2010
Code:
12345    asdf   7777
56789   qwer
11223   tyuo  9999   rty
123444  fghj   3333   bnm  6666

i want my awk function to determine that
"First line has 3 values seperated by tab."
"Second line has 2 values seperated by tab."
"Third line has 4 values seperated by tab."
"Forth line has 5 values seperated by tab."

and then i will use this information in:

Code:
awk 'NR>1 {print "First value: "$1" Second:"$2" Third: "$3 } /home/gcsw/readtext.txt > /home/gcsw/writeresults.txt

and i want to get, for example, fifth value of the forth column by impementing
Code:
awk 'NR=4 {print "$5" } /home/gcsw/readtext.txt > /home/gcsw/writeresults.txt

how can i do it?
# 4  
Old 09-21-2010
Code:
awk 'NR==4 {print $5;next}NR-1 {print "First value: "$1" Second:"$2" Third: "$3 }' file > newfile

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Want to remove a line feed depending on number of tabs in a line

Hi! I have been struggling with a large file that has stray end of line characters. I am working on a Mac (Lion). I mention this only because I have been mucking around with fixing my problem using sed, and I have learned far more than I wanted to know about Unix and Mac eol characters. I... (1 Reply)
Discussion started by: user999991
1 Replies

2. Linux

Kconsole and tabs

Hi Guys i current use Kcosole i have this liitle code that changes the tilte to the current directory that i am in # Set the terminal title to pwd case $TERM in xterm*) precmd() {print -Pn "\e]0;%~ \a"} ;; esac in Kconsole you can have... (0 Replies)
Discussion started by: ab52
0 Replies

3. Shell Programming and Scripting

too many tabs

Hi, I have a file that has too many tabs between columns. I cannot get the tabs out. Basically the tab between column 1 and 2 are fine but between 2/3, 3/4 etc are like 5 tabs. How do I get rid of these 5 tabs so its just 1 tab. thanks (3 Replies)
Discussion started by: phil_heath
3 Replies

4. UNIX and Linux Applications

GVIM with tabs

Hi People, Does gvim latest versions support tabs. I would like to open different files in tabs rather than new windows or split windows. I would like to whether the current version supports it, if it doesn't then how to add such feature. Thanks, :) (2 Replies)
Discussion started by: rimser9
2 Replies

5. Shell Programming and Scripting

spaces or Tabs?

When formatting a script let's say for instance the following: case ${choice} in 1) vi ${tmp1}.tmp # overwrite the tmp1 var with any user changes cp ${tmp1}.tmp ${tmp1} ;; ... (2 Replies)
Discussion started by: llsmr777
2 Replies

6. UNIX and Linux Applications

VIM tabs...

hello i saw a tutorial in this link that explains tabbed editing with VIM. it says: :tabnew :tabe but when I try in my own computer, it says: "Not an editor command" I connect to the Tru64 server using CRT 6.0. what's going wrong? (2 Replies)
Discussion started by: xyzt
2 Replies

7. Shell Programming and Scripting

removing certain tabs

I have a tab delimited file with many lines, one for each record. each line is tab delimited with a tab before the first data field, a tab between each data field, and a tab after the last data field before it moves onto the next line. I need to remove only the preceeding tab before the first... (2 Replies)
Discussion started by: djkane
2 Replies

8. Shell Programming and Scripting

removing tabs

Hi Everyone, Im trying to write a shell script that removes a "newline character followed by a tab" throughout a file. basically it should get rid of it. Here's an example File Before The cat sat on the mat File After The cat sat on the mat This message writing screen has... (7 Replies)
Discussion started by: nbvcxzdz
7 Replies

9. UNIX for Dummies Questions & Answers

Cron Tabs

I am on AIX 5.1 If I have a crontab that looks like this 01 1 * * 6 What does the 6 mean ? if the * means that everyday it should run then why would the 6th day be signified ? Shouldn't it be a * also? Thanks (1 Reply)
Discussion started by: rocker40
1 Replies
Login or Register to Ask a Question