awk to select a column from particular line number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to select a column from particular line number
# 1  
Old 05-07-2006
awk to select a column from particular line number

The awk command awk -F: '{print $1}' test1 gives the first columns of all the lines in file ,is there some command to get a particular column from particular line .
Any help is appreciated.
thanks arif
# 2  
Old 05-07-2006
Yes it is possible to select one particular line from a given file thru awk, but you have to provide here the selection criteria.
# 3  
Old 05-07-2006
My file is comma delimited file ,I have to read the first column from second line and store it in a variable.Can you give me the exact syntax
Thanks
# 4  
Old 05-07-2006
Code:
var=`awk '{getline;print $1;exit}' file`

# 5  
Old 05-08-2006
Quote:
Originally Posted by mab_arif16
My file is comma delimited file ,I have to read the first column from second line and store it in a variable.Can you give me the exact syntax
Thanks
hope this will work

Quote:
vari=`awk -F"," 'NR==2{print $1}' filename`
use nawk on solaris
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Select and copy .csv files based on row and column number

Dear UNIX experts, I'm a command line novice working on a Macintosh computer (Bash shell) and have neither found advice that is pertinent to my problem on the internet nor in this forum. I have hundreds of .csv files in a directory. Now I would like to copy the subset of files that contains... (8 Replies)
Discussion started by: rcsapo
8 Replies

2. Shell Programming and Scripting

awk to select lines with maximum value of each record based on column value

Hello, I want to get the maximum value of each record separated by empty line based on the 3rd column of each row within each record? Input: A1 chr5D 634 7 82 707 A2 chr5D 637 6 82 713 A3 chr5D 637 5 82 713 A4 chr5D 626 1 82 704... (4 Replies)
Discussion started by: yifangt
4 Replies

3. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

4. Shell Programming and Scripting

select entry from consecutive line awk

Hi folks, I have a file with four columns that looks like the following (tab separated) 1 1 1 a 2 2 2 b 3 3 3 c 4 4 4 d I would like to create a file with always 4 columns but where the third entry corresponds to the thirst entry of the next line and so on, to get the following 1 1 2 a... (4 Replies)
Discussion started by: klebsiella
4 Replies

5. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

6. Shell Programming and Scripting

Awk - how to select the column based on day of month

Problem, How can you pass today's date (eg) 18 into Awk and select the field representing the 18th column? I have an output that I want to interact with based on what day it is information=0:0 192:0 5436:0 22:99 0:0 0:0 1234:0 1359:09 DAY=date'+%d' numbrs=`$information | awk... (2 Replies)
Discussion started by: Gizmo1007
2 Replies

7. UNIX for Dummies Questions & Answers

using unix variable in select column in awk

Hi, I have file on below pattern, and i want to write a generic awk to handle all cases. input_file: col1~col2~col3~col4~col5~col6 I need to generate 4 files something like this File1: col1~~col2~~col3 File2: col1~~col2~~col4 File3: col1~~col2~~col5 File4: col1~~col2~~col6 (1 Reply)
Discussion started by: luckybalaji
1 Replies

8. Shell Programming and Scripting

awk to select rows based on condition on column

I have got a file like this 003ABC00281020091005000100042.810001 ... (8 Replies)
Discussion started by: Maruti
8 Replies

9. Shell Programming and Scripting

awk program to select a portion of a line

Hi all, I am new to awk programs.I have a file like this vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd... (3 Replies)
Discussion started by: anju
3 Replies

10. Shell Programming and Scripting

Select matches between line number and end of file?

Hi Guys/Gals, I have a log file that is updated once every few seconds and I am looking for a way to speed up one of my scripts. Basically what I am trying to do is grep through a text file from start to finish once. Then each subsequent grep starts at the last line of the previous grep to... (4 Replies)
Discussion started by: Jerrad
4 Replies
Login or Register to Ask a Question