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
Passing shell variable to NAWK wakhan Shell Programming and Scripting 1 04-23-2008 02:52 AM
passing variable to my script aladdin UNIX for Dummies Questions & Answers 5 06-18-2007 09:34 AM
Passing PL/SQL variable value to Shell Varible ganapati Shell Programming and Scripting 10 01-31-2007 02:17 AM
Passing a variable into an awk script Khoomfire UNIX for Advanced & Expert Users 5 09-05-2006 08:44 AM
passing value to shell variable trynew Shell Programming and Scripting 2 06-24-2002 02:13 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 07-21-2004
bcheaib bcheaib is offline
Registered User
  
 

Join Date: Jul 2004
Location: Beirut
Posts: 25
passing awk variable to the shell script

hi;

i have a file containing lines like:

1|1069108123|96393669788|00963215755711|2|0|941||;serv:Pps6aSyria;first:0;bear

i want to extract the second, third and fourth record of each line and store it in a file ";" seperated

this is what i wrote

while read line
do
A_party=`echo $line |awk -F["|"] '{print $3}'`
B_party=`echo $line |awk -F["|"] '{print $4}'`
time=`echo $line |awk -F["|"] '{print $2}'`

echo $A_party";"$B_party";"$time >> $_outfile
done < $_infile

But the problem is that i am calling three times awk for each line, how can i pass awk variable to the script in order to call awk only one time.

Thanks in advance.
  #2 (permalink)  
Old 07-21-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
An awk one liner should do the trick for the whole set of data

Code:
awk -F'|' '{printf( "%s;%s;%s\n", $2, $3, $4 ) >> "outfile" }' infile
Cheers
ZB
  #3 (permalink)  
Old 07-21-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Or
Code:
awk 'BEGIN{FS="|";OFS=";"}{print $2,$3,$4}' infile > outfile
  #4 (permalink)  
Old 07-21-2004
bcheaib bcheaib is offline
Registered User
  
 

Join Date: Jul 2004
Location: Beirut
Posts: 25
Thanks a lot both worked fine.

question, how can i pass let's say $2 to the script in case i will need it in other place of the script.
remember the subject of my thread.

thanks a lot for your help guys.
Sponsored Links
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:35 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