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
Assign o/p of awk to a variable c2b2 Shell Programming and Scripting 8 04-01-2009 07:50 AM
assign a value to a variable Shivdatta Shell Programming and Scripting 10 01-17-2007 07:40 AM
assign a value to variable markjason Shell Programming and Scripting 3 10-10-2006 02:05 PM
hot to assign output to a variable walnut Shell Programming and Scripting 1 02-22-2006 09:19 PM
assign to variable AkumaTay UNIX for Dummies Questions & Answers 1 05-18-2002 02:11 PM

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-05-2006
HAA HAA is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 24
assign value to variable using AWK

Dear Friends

I have text file as like below,

AAAAA|BHBHBH|VERYSMART
AAAAA| KKKKKK|GOOD
BBBBBB|JJJJJJJ|VERYGOOD
CCCCC|HJHJHJ|BETTER
CCCCC|UUUUU|GOOD

i need to split into seperate files based on column 1 like as below

AAAAA.TXT contains
--------------------
BHBHBH.VERYSMART
KKKKKK.GOOD

BBBBB.TXT contains
---------------------
JJJJJJJ.VERYGOOD

i want to use awk program to handle this,
I would always thankfull to u if give solution to this scenarios.

waiting for reply

Thanks ,
HAA
  #2 (permalink)  
Old 12-05-2006
HAA HAA is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 24
Hi

can i do this way


for h in `cat aa.txt`
do

filename=`echo $h|awk '{print $1}'`
v_filename=filename

if filename=v_filename then
echo filename|awk '{print $1"."$3}' > $v_filename.txt
else
create new file
fi
do

Regardfs,
HAA
  #3 (permalink)  
Old 12-05-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
nawk -f haa.awk myFile.txt

haa.awk:
Code:
BEGIN {
  FS="|"
  OFS=","

  ext=".TXT"
}

{
   out=$1 ext
   print $2 OFS $3 >> out
   close(out)
}
  #4 (permalink)  
Old 12-06-2006
HAA HAA is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 24
I resolved the problem using shell and awk,

Thanks for viewing this thread.

Regards,
HAA
  #5 (permalink)  
Old 12-06-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by HAA
I resolved the problem using shell and awk,

Thanks for viewing this thread.

Regards,
HAA
would you mind posting your solution for the benifits of the others, pls!
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:22 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