LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-13-2005, 09:10 AM   #1
lgualteri
LQ Newbie
 
Registered: Nov 2004
Location: Milan (Italy)
Distribution: RED HAT WS 3
Posts: 2

Rep: Reputation: 0
split files using awk (or similar)


All,

I have a huge file like this:

aaa 222 444 rrr
aaa 234 123 lop
bbb 234 234 kio
bbb 567 345 jjj
ccc 765 567 ghj
ccc 544 678 fre
ccc 444 789 der

I basically need to split the file in a way that:

file aaa.txt shall contain only rows where the first field is aaa:
aaa 222 444 rrr
aaa 234 123 lop

file bbb.txt shall contain only rows where the first field is bbb:
bbb 234 234 kio
bbb 567 345 jjj

etc, etc.


I am sure this is simple and can be done using awk or c-shell script .........


many thanks,
Luca
 
Old 06-13-2005, 09:17 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
I don't know c-shell nor awk, but in bash :
Code:
while read line; do
    pre=`echo $line | cut -d' ' -f1`
    echo $line >> $pre.txt
done < file.txt
where file.txt is your huge file
 
  


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
Split large file in several files using scripting (awk etc.) chipix Programming 14 10-29-2007 11:16 AM
How do I cut out a specific piece of a html page (using sed/awk or similar)? bomix Linux - General 2 10-08-2005 04:30 PM
similar to dpkg-split on rpm based systems? lil_becky Linux - Newbie 1 01-19-2005 11:53 PM
awk files alaios Linux - General 7 05-13-2003 05:56 AM
How to rejoin split files SharpyWarpy Linux - General 2 02-07-2003 02:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:15 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