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 11-04-2007, 11:20 PM   #1
loplayers
LQ Newbie
 
Registered: Oct 2007
Posts: 14

Rep: Reputation: 0
how to get the second column and first row data from a file???


there is a file call 'abc':
1 abc 123
2 def 456
3 erew 678

But i use two command that using 'cut' and 'head' command
How can i get 'abc' into a variable with one command only???
 
Old 11-04-2007, 11:23 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Code:
myvar=$(head -n 1 abc |cut -d" " -f2)
 
Old 11-04-2007, 11:55 PM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Or
Code:
myvar=$(awk 'NR==1{print $2}' abc)
 
Old 11-05-2007, 08:35 PM   #4
loplayers
LQ Newbie
 
Registered: Oct 2007
Posts: 14

Original Poster
Rep: Reputation: 0
if i want to get the last data with column2. then, like the below command?
myvar=$(tail -n 1 abc |cut -d" " -f2)

Last edited by loplayers; 11-05-2007 at 08:37 PM.
 
  


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
Gnumeric's worksheet doesn't display row and column headers correctly frazum Linux - Software 4 07-09-2007 12:53 PM
vi editor - how to delete a character in each row of a column? flipwhy Linux - Newbie 6 01-22-2007 03:12 PM
Parsing rows and column data from a file using perl dav_y2k Programming 1 10-08-2006 12:57 PM
Transposing a column into a row mayyash Linux - General 1 09-30-2005 03:23 AM
How to write the contents of a column as a row in linux markraem Linux - Software 4 07-17-2004 08:35 PM


All times are GMT -5. The time now is 06:35 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration