Read last word of nth line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read last word of nth line
# 1  
Old 11-02-2010
Power Read last word of nth line

Hi people;

i want to read the last word of the 14th line of my file1.txt. Here is the EXACT 14th line of the file.
Code:
  250  SectorPortnum=3,AuxPortInUngo=2,PortDeviceGroup=1,PortDeviceSet=1,PorDevice=1  20                   >>> Set.

i have to get the word Set. how can i call it and also how can i assign it to a variable? the field separators are space. i donot know if you need these spaces:

before 250 there are 2 spaces.
between 250 and Sector.. there are 2 spaces.
between ...PorDevice=1 and 20 there are 2 spaces.

between 20 and >>> there are
# 2  
Old 11-02-2010
Code:
awk 'NR==14 {print $NF}' file1.txt
# if the dot has to be removed
awk 'NR==14 {sub(/\.$/,"",$NF); print $NF}' file1.txt

This User Gave Thanks to zaxxon For This Post:
# 3  
Old 11-02-2010
with sed..
Code:
VAR=$(sed -n '14s/.* >>* \(.*\).$/\1/p' inputfile)


Last edited by michaelrozar17; 11-02-2010 at 07:57 AM..
This User Gave Thanks to michaelrozar17 For This Post:
# 4  
Old 11-02-2010
thanks for all your replies Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

How to read the nth character from the line.?

I have Index Line and I tried to get the 9th character from the file and to check the character is "|" or not. Shell Scripting. Sample Index file. "91799489|K8E|188.004.A.917994892.1099R.c.01.pdf|2013|10/15/2014|002|B|C|C"... (3 Replies)
Discussion started by: pavand
3 Replies

2. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

3. Shell Programming and Scripting

How to grep nth word in line?

my input file content is like this GEFITINIB 403 14 -4.786873 -4.786873 -1.990111 0.000000 0.000000 -1.146266 -39.955912 483 VANDETANIB 404 21 -4.754243 -4.754243 -2.554131 -0.090303 0.000000 -0.244210 -41.615502 193 VANDETANIB 405 21 -4.737541 -4.737541 -2.670195 -0.006006 0.000000 -0.285579... (4 Replies)
Discussion started by: chandu87
4 Replies

4. Shell Programming and Scripting

Read a file from the nth line on

I have a script which reads from a job file and executed the scripts in the job file in sequence. #! /bin/ksh set -x while read line do $line.ksh if # mail the team fi done <"$file" The job file will be like abcd efgh ijkl mnop qrst This is working fine. I need to add... (2 Replies)
Discussion started by: nw2unx123
2 Replies

5. Shell Programming and Scripting

Get the nth word of mth line in a file

Hi.. May be a simple question but I just began to write unix scripts a week ago, for sorting some huge amount of experiment data, so I got no common sense about unix scripting and really need your helps... The situation is, I want to read the nth word of mth line in a file, and then store it... (3 Replies)
Discussion started by: freezelty
3 Replies

6. Shell Programming and Scripting

How to read nth word from delimited text file?

Hi i am new in scripting how i can get 2 elements from first line of delimited txt file in shell scripts. AA~101010~0~AB~8000~ABC0~ BB~101011~0~BC~8000~ABC~ CC~101012~0~CD~8000~ABC0~ DD~101013~0~AB~8000~ABC~ AA~101014~0~BC~8000~ABC0~ CC~101015~0~CD~8000~ABC~ can anyone plse help?... (3 Replies)
Discussion started by: sushine11
3 Replies

7. Shell Programming and Scripting

Read file from nth line to specific character

Hi, I want to read the file from nth line (where n is an integer) to until I encounter @ char. Can any one please help me how to do this? Thanks. (3 Replies)
Discussion started by: laalesh
3 Replies

8. Shell Programming and Scripting

how to find third(nth) word in all line from a file

For example i'm having the below contents in a file: expr is great when you want to split a string into just two parts. The .* also makes expr good for skipping a variable number of words when you don't know how many words a string will have. But expr is lousy for getting, say, the fourth word... (2 Replies)
Discussion started by: bangarukannan
2 Replies

9. UNIX for Dummies Questions & Answers

query on how to search for a line and read 4th word from that line

Assume I have a text file as below: me con pi ind ken pras ur me con rome ind kent pras urs pintu con mys ind pan pras ki con kit ind sys My requirement, I need to search for "con rome" and if exists, then print 4th word from rome, i.e in above example, since "con rome"... (4 Replies)
Discussion started by: jaggesh
4 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question