Extract third field of third line


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers Extract third field of third line
# 1  
Old 04-28-2009
Extract third field of third line

Hi, how do I extract the third field of the first line?

I know how to get the first line or the third field of a file, but I can't get the single entry.

awk 'NR==1' file.txt

awk '{print $3}' file.txt

Please tell me how to combine these.

And how do I set this value into a variable?

var='awk "NR==1" file.txt'
?

But now I have to "eval" this $var, right?

I want to use $var in another expression.

Thanks for your help.
# 2  
Old 04-29-2009
var=$(awk 'NR==3{print $3}' file.txt)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

2. UNIX for Dummies Questions & Answers

Ps output field extract

This is the output from ps -ef cmd . I have to extract the fourth (C) and the seventh (TIME) field root 3932344 3801216 Apr 08 - 0:00 /usr/sbin/rsct/bin/ERrmd root 3997836 1 0 Apr 08 - 0:00 /usr/sbin/uprintfd root 4128894 3801216 0 Apr 08 - 0:09... (3 Replies)
Discussion started by: Anu_1
3 Replies

3. Shell Programming and Scripting

Extract lines whose third field is 0

Hi, I have a file with colon separated values like below. How can i get those lines whose third field is 0 (zero). In the below example, lines starting with stapler and tempo has its third field as 0 $ cat list.txt galaxy:b:5:world stapler:a:0:hello abc:a:4:stomper kepler:uic:5:jam... (8 Replies)
Discussion started by: John K
8 Replies

4. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

5. Shell Programming and Scripting

sed to replace a field from a line with another field

i have something like this, cat filename.txt hui this si s"dfgdfg" omeone ipaddress="10.19.123.104" wel hope this works i want to replace only 10.19.123.104 with different ip say 10.19.123.103 i tried this sed -i "s/'ipaddress'/'ipaddress=10.19.123.103'/g" filename.txt ... (1 Reply)
Discussion started by: vivek d r
1 Replies

6. Shell Programming and Scripting

Compare Field in Current Line with Field in Previous

Hi Guys I have the following file Essentially, I am trying to find the right awk/sed syntax in order to produce the following 3 distinct files from the file above: Basically, I want to print the lines of the file as long as the second field of the current line is equal to the... (9 Replies)
Discussion started by: moutaye
9 Replies

7. UNIX for Dummies Questions & Answers

Extract a certain field from a CSV?

EDIT: This problem has been solved thanks to the help of scottn. Okay, so I have a CSV. Let's say it has the following entries in it: Jackie Chan,1954,M Chuck Norris,1930,M Bruce Lee,1940,M How would I, for example, extract the gender out of a certain person, maybe based on the year of... (12 Replies)
Discussion started by: chickeneaterguy
12 Replies

8. Shell Programming and Scripting

how to extract last occurence of the field

path = /first/second/third/fourth. i want to extract /first/second/third from path.my program something like this .... path=/first/second/third/fourth noc=`echo $path|tr '/' '\n'|wc -w` var='echo $noc|cut -d'/' -f 1-$noc --> is giving error. why $noc is not working here.any other... (3 Replies)
Discussion started by: kcp_pavan
3 Replies

9. Shell Programming and Scripting

need to extract field of characters in a line

Hello, Below is my input file's content ( in HP-UX platform ): ABCD120672-B21 1 ABCD142257-002 1 ABCD142257-003 1 ABCD142257-006 1 From the above, I just want to get the field of 13 characters that comes after 'ABCD' i.e '120672-B21'... . Could you please let me know the shell script... (3 Replies)
Discussion started by: jansat
3 Replies

10. Shell Programming and Scripting

AWK line by line instead of field by field?

I've been using a lot of awk lately for csv files. But I've been using awk for csv files that contain 32 fields per line. For the first time, I've been given a csv file that contains one field per line (13 fields in each csv file). I need to check that a specific field, or line contains a... (2 Replies)
Discussion started by: yongho
2 Replies
Login or Register to Ask a Question