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
split files into specified number of output files Migrainegirl UNIX for Dummies Questions & Answers 4 05-13-2008 09:38 AM
Split files using Csplit savitha UNIX for Dummies Questions & Answers 7 12-01-2007 11:55 AM
Split A File Into 2 Files dummy_needhelp Shell Programming and Scripting 7 11-04-2007 07:36 PM
Help please!Split files according to index onthetopo Shell Programming and Scripting 9 05-11-2007 09:37 AM
Split command malaymaru Shell Programming and Scripting 1 11-18-2005 02:40 AM

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 12-13-2005
m_subra_mani m_subra_mani is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 1
awk command to split in to 2 files

Hi,
I have a problem in grepping a file for 2 strings and writing them to 2 appropriate files. I need to use the awk command and read the file only once and write to the appropriate file.
My file is very huge in size and it is taking a long time using cat command and grep command.
Can anyone help me with using the awk command for this?
  #2 (permalink)  
Old 12-13-2005
akrathi akrathi is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 41
You may modify this to work for your requirement
Thanks
Ashok

awk '
{
if ( substr($0,1,1) == "A")
print $0 >>FILE1
if ( substr($0,1,1) == "B")
print $0 >>FILE1

}' FILE1="file_1" FILE2="file_2" test.data
~
  #3 (permalink)  
Old 12-13-2005
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
If your file is really as big as you suggest you would get much better performance using perl.
  #4 (permalink)  
Old 12-13-2005
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
  
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 637
instead of using a cat and then a grep --- just grep directly out of the file ...

Code:
this ...
    grep string /dir/file

not this ...
    cat /dir/file | grep string
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 05:21 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