LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-02-2013, 09:10 AM   #1
ultraclassic
LQ Newbie
 
Registered: Aug 2013
Posts: 6

Rep: Reputation: Disabled
Selecting a specific record from a file


I need a simple way to select a particular record in a file. Let's say I have a file with 10 filenames in it (each a record) and I want to select the 6th record and assign that filename to a variable. I was thinking awk using the NR built-in would be an easy way to do this but I can't quite get the command right.
 
Old 10-02-2013, 09:22 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,356

Rep: Reputation: 833Reputation: 833Reputation: 833Reputation: 833Reputation: 833Reputation: 833Reputation: 833
So what awk command did you try and what were the results (if any)
 
Old 10-02-2013, 09:28 AM   #3
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,718

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Code:
WHICH=6
awk "{if (NR == $WHICH) print \$0}" < file
works for me
 
Old 10-02-2013, 10:09 AM   #4
ultraclassic
LQ Newbie
 
Registered: Aug 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
That's exactly what I needed, thank you very much!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Without selecting other text to copy, I want to be able to paste specific text el_gallo_azul Linux - Newbie 15 06-06-2013 04:43 AM
wget, download specific links into specific file names Si14 Linux - Software 1 04-30-2013 01:42 AM
Text file manipulation: selecting specific lines/columns using awk and print CHARL0TTE Linux - Newbie 2 02-27-2010 02:40 AM
Selecting a specific AP MAC address in rc.inet1.conf Alstare Slackware 6 11-19-2008 02:20 PM
selecting specific files slack66 Linux - Newbie 1 02-14-2004 07:52 AM


All times are GMT -5. The time now is 12:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration