The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
noob help needed ace_face Linux 1 04-20-2008 08:23 PM
Unix Noob, wat do i need etc skylin3fr3ak UNIX for Dummies Questions & Answers 2 02-24-2008 11:17 AM
complete unix noob (sorry) Blastman UNIX for Dummies Questions & Answers 2 12-23-2007 10:34 PM
I am a unix noob alt+f4 UNIX for Dummies Questions & Answers 4 04-28-2006 09:01 PM
Noob learning Unix: backup commands lotusx UNIX for Dummies Questions & Answers 1 06-28-2005 01:50 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-31-2008
AnnaLynn AnnaLynn is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 10
unix noob help with awk?

Hi
I'm really new to this so sorry if this is trivial

What I'm trying to do is take a file with 3 columns of numbers and cat all the entries of the second and third columns which have the same entry in the first column into a file with the number from the first column in the name. So say

1 3 4
1 3 5
1 4 6 > something1.txt

2 3 5
2 5 7 > something2.txt

Tried using awk but I'm not very good
  #2 (permalink)  
Old 03-31-2008
mirusnet's Avatar
mirusnet mirusnet is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 146
Code:
for i in 1 2 3 4 5 6 7 8 9 0; do cat file | egrep "^$i" >$i ; done
  #3 (permalink)  
Old 04-01-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
As an aside, cat file | egrep pattern is better expressed as egrep pattern file, without the cat.
  #4 (permalink)  
Old 04-01-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
With awk (input file is read only once) :
Code:
awk '{print > "something" $1 ".txt"}' inputfile
Jean-Pierre.
  #5 (permalink)  
Old 04-01-2008
AnnaLynn AnnaLynn is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 10
Cool

Quote:
Originally Posted by aigles View Post
With awk (input file is read only once) :
Code:
awk '{print > "something" $1 ".txt"}' inputfile
Jean-Pierre.
Brilliant! Works like a dream
  #6 (permalink)  
Old 04-01-2008
AnnaLynn AnnaLynn is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 10
And if I wanted to use the input filename in the output file's names? How owuld I do that?

I have the whole thing in a big script:

cat listoffilenames | while read line; do awk{the stuff above but also want the $line name in here too but it doesnt evaluated $line for me, instead prints $line} $line
  #7 (permalink)  
Old 04-01-2008
AnnaLynn AnnaLynn is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 10
Basically what I am asking is

How do I get this to work:

awk '{print > "something$inputfile" $1 ".txt"}' $inputfile

?

I've tried
awk '{print > "something"$inputfile"" $1 ".txt"}' $inputfile

But doesnt work?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0