LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 12-08-2006, 02:20 PM   #1
Nkunzis
LQ Newbie
 
Registered: Dec 2006
Posts: 3

Rep: Reputation: 0
awk in loop How to


hi memeber
how can i use awk in a loop to get the columns of a table.such as


for count in ` cat file | awk '{ print $1 }' `

but i want to get another column
ın each loop

ıs it possible to do something like this

col=1

for count in ` cat file | awk '{ print $col }' `
do
--
-
--
let col=`expr col + 1 #get next column number
done
 
Old 12-08-2006, 02:43 PM   #2
int0x80
Member
 
Registered: Sep 2002
Location: Cincinnati
Distribution: Debian GNU/Linux
Posts: 310

Rep: Reputation: 31
Do I understand correctly that you want the xth column for the xth line? E.g. 1st column on the 1st line, 2nd column on the 2nd line, etc?
 
Old 12-09-2006, 04:28 AM   #3
Nkunzis
LQ Newbie
 
Registered: Dec 2006
Posts: 3

Original Poster
Rep: Reputation: 0
awk column

to get xth column the xth has already been taken care of
 
Old 12-10-2006, 01:34 PM   #4
int0x80
Member
 
Registered: Sep 2002
Location: Cincinnati
Distribution: Debian GNU/Linux
Posts: 310

Rep: Reputation: 31
Perhaps try explaining what you are attempting to do? If you want every column from every row, you could use two for loops...
Code:
for each row;
    for each column;
...but I'm assuming you're doing something with the items? Otherwise why not just dump the original output?
 
  


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
awk: loop through ldap aliases tonedeaf1969 Programming 6 11-17-2006 11:56 AM
awk "for loop" question rharvey@cox Programming 5 05-03-2006 06:12 AM
for loop only works properly on first loop symo0009 Programming 1 12-25-2005 05:17 PM
How to loop or sort in bash, awk or sed? j4r0d Programming 1 09-09-2004 03:22 AM
awk - simple 'for' loop doing my nut... davee Programming 2 06-30-2004 08:54 AM


All times are GMT -5. The time now is 05:48 AM.

Main Menu
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