returning a column number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting returning a column number
# 1  
Old 07-06-2007
returning a column number

Hi all,

i was doing a small program where if i was to be given the first 3 letters of any month i.e. in the form of Jan or Apr then it would return the column number where it finds a match. To do this i created a 12 element array of months with first 3 letters and if i echo'ed the contents of the array, piped it into another command that would return me a column number where it matched. i thought awk could do this by replacing 'print' with 'find' but it doesn't work although it doesn't give an error message. Is there a command already out there that does this?

thanks

Mani
# 2  
Old 07-06-2007
Mani,

Can you post your problem ?

that would help us to give currect solution.
# 3  
Old 07-06-2007
Hi,maybe this can help you

I suppose you want to scan a file, and then find the file's line which contain Abbrevision for MONTH, and then print the line's line number.

Follow maybe can help u, just for you reference:

The file content(a.txt):
Code:
this is Mar
now come a Feb
then another Mar
he a Jun comes

The script:

Code:
read mon
echo "The line number which contain ${mon} is as follow:"
sed "/$mon/=" a.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract number from column

I have a lot of file with a lot of lines following the same pattern the lines go like this: alpha_9/output- -413.74928476 2.6116 and I want it to be: 9 -413.74928476 2.6116 thanks for the help (5 Replies)
Discussion started by: galboski
5 Replies

2. Shell Programming and Scripting

Split column data if the table has n number of column's with some record

Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records Table --------- Col1 col2 col3 col4 ....................col20 1 2 3 4 .................... 20 a b c d .................... v ... (11 Replies)
Discussion started by: Priti2277
11 Replies

3. Shell Programming and Scripting

Split column data if the table has n number of column's

please write a shell script Table -------------------------- 1 2 3 a b c 3 4 5 c d e 7 8 9 f g h Output should be like this --------------- 1 2 3 3 4 5 7 8 9 a b c c d e f g h (1 Reply)
Discussion started by: Priti2277
1 Replies

4. Shell Programming and Scripting

Help with compare two column and print out column with smallest number

Input file : 5 20 500 2 20 41 41 0 23 1 Desired output : 5 2 20 0 1 By comparing column 1 and 2 in each line, I hope can print out the column with smallest number. I did try the following code, but it don't look good :( (2 Replies)
Discussion started by: perl_beginner
2 Replies

5. Shell Programming and Scripting

Summing a number column

hi All, i have a file in which only one column is there., test.txt ====== -900.01 -900.02 -900.03 -900.04 -900.05 -900.06 -900.07 -900.08 -900.09 900.01 900.02 900.03 900.04 900.05 (4 Replies)
Discussion started by: mechvijays
4 Replies

6. UNIX for Dummies Questions & Answers

Dividing a column by it's first number

Hi! Is there an easy way (maybe using awk??) to divide the values of one column of the file by it's first entry.. If I have a column: 3 4 5 6 7 I would like to divide it by 3. I want to do this for more than 100 files, so it wouldn't be practical to open file by file and... (26 Replies)
Discussion started by: cosmologist
26 Replies

7. HP-UX

Division returning a negative number

Hi All, Just faced an interesting thing in HP-UX. I was dividing 2955334616 / 2 by using echo `expr 2955334616 / 2` , and this ofcourse which expects 1477667308 to be returned. But I am getting -669816340 and I am :wall: how exactly this is possible. It is not one of the compliments (Ones or... (4 Replies)
Discussion started by: mail2sanand
4 Replies

8. UNIX for Dummies Questions & Answers

Grep by column number

I have a data file that is arranged like this: Marketing Ranjit Singh Eagles Dean Johnson FULL Marketing Ken Whillans Eagles Karen Thompson FULL Sales Peter RobertsonGolden TigersRich Gardener PART President Sandeep Jain Wimps Ken Whillans CONT... (7 Replies)
Discussion started by: hitman247m
7 Replies

9. Shell Programming and Scripting

column number, awk, help

All, $ cat myf.txt A|xyz|1000|mm B|9000|xyz|ss C|BDE|2000|kk D|xyz|1000|nn I am searching "xyz" $ awk -F "|" ' {for(k=0;k<=NF;k++) if ( $k == "xyz" ) print "line="NR"(column="k")" }' myf.txt Output: line=1(column=2) line=2(column=3) line=4(column=2) (2 Replies)
Discussion started by: jkl_jkl
2 Replies

10. Shell Programming and Scripting

printf returning unknown number

Hi, Can anybody tell me why this function returns 49? printf "%d\n" \'10 I don't understand what the \ and ' are there for? thanks!!! (1 Reply)
Discussion started by: m0nk3y
1 Replies
Login or Register to Ask a Question