one file broken down into two


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting one file broken down into two
# 1  
Old 11-20-2009
one file broken down into two

Hi,

I guess the common theme for command lines is to take what you want out of a file and put it into another file. I am wondering if there are ways of putting what you dont want into a file aswell.

so heres an example:

Code:
1
3
4
5
7
8

so if i use this code, I get values above 7 and those below 2, and they go into file 1. But is there a way of putting those left out into a separate file? I know the alternative solution is to write a seperate code for those values left out (in this example it would be values between 2-7) but there must be a faster way.

Code:
awk ' $1<=2 || $1>=7' FILE1

thanks

Kyle
# 2  
Old 11-20-2009
awk is powerful

hey,
Maybe you can change the output file(s) dynamically.
for example:

Code:
awk '($1<=2 || $1>=7) ? outfile = "out1" : outfile = "out2" {print > outfile}' inputfile

# 3  
Old 11-20-2009
Another way:

Code:
awk '$1<=2 || $1>=7{print $0 > "file1";next}' file > file2

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to identify broken lines in a file?

Hi, I have a 100 byte length fixed width file . In that three rows are broken and went off to next line. How can I identify the broken lines? E.g. ABCD1234MNRD4321 abcd1234mnrd 4321 As you can see in my example my second row with small case alphabets is broken... (5 Replies)
Discussion started by: okkadu
5 Replies

2. UNIX for Dummies Questions & Answers

broken pipe

I know what causes 'broken pipe' errors, but I can't understand why I can get it (only occasionally) with my example: ps -ef | grep "\./ans$" | grep -v grep Basically I'm searching the ps output looking for the process I'm interested in and excluding the process that is grepping for the... (2 Replies)
Discussion started by: fhew
2 Replies

3. Shell Programming and Scripting

broken pipe for ftp file transfer

hi i am trying to connect to a remote server and trying to uploa a file. during upload i am getting ":Broken pipe" error please help (0 Replies)
Discussion started by: Satyak
0 Replies

4. UNIX for Advanced & Expert Users

Converting .ps file to .pdf file from where it is broken

In my folder Testing I have 5 files. 1.ps 2.ps 3.ps 4.ps 5.ps Now When I am converting this .ps file to .pdf file then it is broken at the 2.ps file. And I created one status.txt file where this broken file 2.ps is stored. Now How shell I start to convert .ps file to .pdf file from... (5 Replies)
Discussion started by: sunitachoudhury
5 Replies

5. UNIX and Linux Applications

pipe broken

hi i have a server, and i have a web site and i installed apache in the /usr/local/apache/logs i have a file and i have this problem (32)Broken pipe: core_output_filter: writing data to the network plz help me how i can resolve this plz it's urgent th (1 Reply)
Discussion started by: abir2
1 Replies

6. UNIX for Dummies Questions & Answers

Broken Pipe

Hi I tried to open the man page of sh and piped to `pg`. Normally while reading a file page by page using `pg`, if we wanna quit at the middle of file, we give "q" near the colon mode. Ex1: $cat file1 | pg hi how r u : (page1) now press "return key", it will go to next page yes i ... (3 Replies)
Discussion started by: ramkrix
3 Replies

7. UNIX for Advanced & Expert Users

Broken Pipe

Hi I tried to open the man page of sh and piped to `pg`. Normally while reading a file page by page using `pg`, if we wanna quit at the middle of file, we give "q" near the colon mode. Ex1: $cat file1 | pg hi how r u : (page1) now press "return key", it will go to next page yes i ... (1 Reply)
Discussion started by: ramkrix
1 Replies

8. Linux

is grep -i broken?

Is grep -i (case insensitive) broken? If not, can someone explain to me why the third grep fails with no output? $ echo DBI DBH | grep DB DBI DBH $ echo dbi dbh | grep -i 'DB' dbi dbh $ echo DBI DBH | grep -i DB $ grep --version grep (GNU grep) 2.5.1 Copyright 1988, 1992-1999,... (2 Replies)
Discussion started by: tphyahoo
2 Replies

9. UNIX for Advanced & Expert Users

Broken

Ok i am running Linux, or rather was. I can not longer do anything. This was a dns server amoungst other things. It will no longer boot. I have used a startup disk, but how can i recover the OS? I need help and urgently. Please someone thanks (3 Replies)
Discussion started by: ollyparkhouse
3 Replies
Login or Register to Ask a Question