The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script required to get a required info from file. Pls. help me. ntgobinath Shell Programming and Scripting 2 05-31-2008 05:34 AM
SSL help required binums HP-UX 0 05-03-2006 11:03 PM
help required thaduka UNIX for Dummies Questions & Answers 5 02-14-2006 09:20 PM
Help required on DBX Sumanth SUN Solaris 1 07-29-2004 06:54 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-18-2008
Registered User
 

Join Date: Apr 2008
Posts: 2
Help required on awk

Hi,

I have a fixed with file, which have almost 10 records

Sample File:
------------
AR 100 TTT
BC 200 SSS
DA 199 YYY
AR 500 RRR
PO 300 QQQ
PB 800 PPP
PC 150 OOO
AR 111 CCC
AD 321 LLL

I Have to check for first two charactors and if its 'AR' i have to save those records to one file, say FILE1 or i have to save to yet another file,SAY FILE2

OUTPUT
-------

FILE1:
-------
AR 100 TTT
AR 500 RRR
AR 111 CCC

FILE2:
------
BC 200 SSS
DA 199 YYY
PO 300 QQQ
PB 800 PPP
PC 150 OOO
AD 321 LLL

Can i achieve this using awk or is there any way to do this?

Thanks in advance
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-18-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,453
Code:
awk '{ if ( $0 ~ "^AR" ) { print > "file_one" } else { print > "second_one" } }' filename
please search the forums
Reply With Quote
  #3 (permalink)  
Old 04-18-2008
Registered User
 

Join Date: Apr 2008
Posts: 2
i think this command is not working, i am getting this error

awk: syntax error near line 1
awk: illegal statement near line 1
awk: bailing out near line 1


i am new to shell scripting can anyone help me?
Reply With Quote
  #4 (permalink)  
Old 04-18-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,608
Use nawk or /usr/xpg4/bin/awk on Solaris.

Regards
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0