Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-02-2013, 10:10 AM   #1
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, 10:22 AM   #2
Senior Member
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,595

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

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

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


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 05:43 AM
wget, download specific links into specific file names Si14 Linux - Software 1 04-30-2013 02:42 AM
Text file manipulation: selecting specific lines/columns using awk and print CHARL0TTE Linux - Newbie 2 02-27-2010 03:40 AM
Selecting a specific AP MAC address in rc.inet1.conf Alstare Slackware 6 11-19-2008 03:20 PM
selecting specific files slack66 Linux - Newbie 1 02-14-2004 08:52 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:32 AM.

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