LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 10: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, 10:23 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

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

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Or
Code:
myvar=$(awk 'NR==1{print $2}' abc)
 
Old 11-05-2007, 07: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 07:37 PM.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:37 AM.

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
Open Source Consulting | Domain Registration