LinuxQuestions.org
Visit Jeremy's Blog.
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 10-06-2013, 12:26 AM   #1
sryzdn
Member
 
Registered: Feb 2013
Posts: 273

Rep: Reputation: 9
awk certain rows


Hi,

I have a file like this:

Quote:
ZZ 0.0000800000 1.8669400000 -0.2141500000
O0 -0.0001300000 1.8659400000 1.7686600000
ZZ 1.6189500000 0.9335900000 2.4187200000
O1 1.6191799200 0.9345838600 4.4015399500
ZZ -1.6173400000 4.6683936172 -0.2141500000
O3 -1.6175500000 4.6673936172 1.7686600000
ZZ 0.0015300000 3.7350436172 2.4187200000
O4 0.0017599200 3.7360374772 4.4015399500
ZZ -1.6158900000 6.5364972344 2.4187200000
O5 -1.6156600800 6.5374910944 4.4015399500
ZZ 3.2381300000 1.8669400000 -0.2141500000
O6 3.2379200000 1.8659400000 1.7686600000
I want to pour all the lines that start with "ZZ"in one file and the rest in another. How can I do it with awk?
 
Old 10-06-2013, 12:37 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Try redirection inside the awk code:
Code:
awk '/^ZZ/{print > "ZZ.txt"}!/^ZZ/{print > "others.txt"}' file
 
1 members found this post helpful.
  


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 comparing 2 rows and counting secret Linux - Newbie 7 03-12-2013 08:36 PM
[SOLVED] awk columns to rows not working toney_e Programming 13 09-25-2012 01:52 AM
[SOLVED] AWK (or TCL/TK): Matching rows and columns between multiple files Euler2 Programming 6 05-30-2011 06:31 PM
[SOLVED] merging files with different number of rows using awk linux002 Linux - Newbie 8 05-05-2011 03:26 PM
I there a way to tell awk to select rows instead of collums jsandro7 Linux - Newbie 2 06-14-2004 10:58 AM

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

All times are GMT -5. The time now is 10:53 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration