unix noob help with awk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unix noob help with awk?
# 1  
Old 03-31-2008
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 Smilie
# 2  
Old 03-31-2008
Code:
for i in 1 2 3 4 5 6 7 8 9 0; do cat file | egrep "^$i" >$i ; done

# 3  
Old 04-01-2008
As an aside, cat file | egrep pattern is better expressed as egrep pattern file, without the cat.
# 4  
Old 04-01-2008
With awk (input file is read only once) :
Code:
awk '{print > "something" $1 ".txt"}' inputfile

Jean-Pierre.
# 5  
Old 04-01-2008
Tools

Quote:
Originally Posted by aigles
With awk (input file is read only once) :
Code:
awk '{print > "something" $1 ".txt"}' inputfile

Jean-Pierre.
Brilliant! Smilie Works like a dream
# 6  
Old 04-01-2008
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  
Old 04-01-2008
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Noob trying to improve

Hi everyone! This is my first post here, I hope that I will not already be violating any rule! I also would like to apologize in advance as my post will definitely be a noob post... please have patience and faith :rolleyes:! Now that I have set the ground rules :D:D, my objective is trying... (39 Replies)
Discussion started by: Ardzii
39 Replies

2. Shell Programming and Scripting

noob question - is awk the tool to clean dirty text files?

Hi, nevermind. I think I've found the answer. It appears I was looking for index, match, sub, and gsub. I want to write a shell script that will clean the html out of a bunch of files and format the data for import into excel. Awk seems like a powerful tool, but it seems oriented to... (1 Reply)
Discussion started by: yogert909
1 Replies

3. UNIX for Dummies Questions & Answers

Noob on Unix.

This may seem really easy to alot of you but i am a real noob on unix. I have been set the task to make a script which will answer a query. Basically I will have made files for people and i want to be able to search for a persons file and then select certain variables from the files. e.g... (7 Replies)
Discussion started by: bobtheb
7 Replies

4. Linux

noob help needed

i'm having trouble putting together a program :( any help would be much appreciated! Write a Shell Program to automate the process of collecting assignments from the directories of students of any specified class. The person running the program should be able to pass a parameter to the... (1 Reply)
Discussion started by: ace_face
1 Replies

5. UNIX for Dummies Questions & Answers

Unix Noob, wat do i need etc

Hey everyone I am currently starting University, (Aus) and i am required to study Unix as apart of my study. We have gone through the basics in orientation but here at home they said i can access my files through the 'ssh' command. All i need to know is: - How will my wireless internet be... (2 Replies)
Discussion started by: skylin3fr3ak
2 Replies

6. UNIX for Dummies Questions & Answers

complete unix noob (sorry)

This is my first time in this forum so, Hello to all!!! I have been supporting windows based machines for a few years now and I have been writing batch files to do certain tasks for what seems like an age. I've recently started a new job (as it support) and my new colleagues have said,... (2 Replies)
Discussion started by: Blastman
2 Replies

7. Shell Programming and Scripting

Shell Noob

Hi all, I am trying to write a shell script that will move files from one directory to another, the only thing is I want to to check loads of different source directory and move the files to loads of different directories. I am totally new to shell scripts but not to UNIX (although I would... (16 Replies)
Discussion started by: Sax
16 Replies

8. UNIX for Dummies Questions & Answers

complete noob

Hi all, This is my first post. I am a complete noobie to the UNIX OS, I have an iMac G5 with the unix shell built in and am interested in learning how to use it to do things useful with it, but have no idea where to start. I have read over the basic commands but they haven't helped me much yet.... (3 Replies)
Discussion started by: avdrummerboy
3 Replies

9. UNIX for Dummies Questions & Answers

I am a unix noob

Hello i am new to this forum. I signed up here really to ask one question. I recentaly got a old unix server from my work and i never really understood what unix is or what is does. Dont get me wrong i and very smart with computers as long as its windows, mac, or linux i can use them all but i... (4 Replies)
Discussion started by: alt+f4
4 Replies

10. UNIX for Dummies Questions & Answers

Noob learning Unix: backup commands

I am trying to learn some unix here and i have some question that i would like to ask: What's the most basic backup command? What is the command to pause a backup? What is the command to resume backup? Can we backup a job that is running ? How can we pause the backup of the job and than... (1 Reply)
Discussion started by: lotusx
1 Replies
Login or Register to Ask a Question