Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

usage of Awk inside awk results....
Hello, can someone help me in solving my "awk" doubt..

I have an input file as shown below:

XYZ Company.FFF.MKS
XYZ Company.FFF.MKS|ABC-Designer
XYZ Company.FFF.MKS|ABC-Designer|User1
XYZ Company.FFF.MKS|DEF-Engineer|User2
XYZ Company.FFF.MKS-FCSF|DEF-Engineer|X-User2

And I need to tweak the above file into:

XYZ Company.FFF.MKS
XYZ Company.FFF.MKS|Designer
XYZ Company.FFF.MKS|Designer|User1
XYZ Company.FFF.MKS|Engineer|User2
XYZ Company.FFF.MKS-FCSF|Engineer|X-User2

I tried to get the output file using WHILE loop and "cut " combination
but my input file has around 30,000 lines and it takes a long time to
process with the below script.
-----------------------------------------------------------------
exec<input.txt

while read line
do
first=`echo $line|awk -F"|" '{print $1}'`
second=`echo $line|awk -F"|" '{print $2}'|awk -F"-" '{print $2}'`
third=`echo $line|awk -F"|" '{print $3}'`

echo "$first|$second|$third" >> output.txt

done
-----------------------------------------------------------------

I am not sure how to use it directly with awk like..

cat input.txt|awk -F"|" '{print $1"|"$2 and awk on $2 with -F"-"
option}

can someone give me some suggestion please.

Thanks in advance.


Report this thread to moderator Post Follow-up to this message
Old Post
karthik.prabaharan@gmail.com
04-18-05 08:55 PM


Re: usage of Awk inside awk results....
karthik.prabaharan@gmail.com wrote:
> Hello, can someone help me in solving my "awk" doubt..
>
> I have an input file as shown below:
>
> XYZ Company.FFF.MKS
> XYZ Company.FFF.MKS|ABC-Designer
> XYZ Company.FFF.MKS|ABC-Designer|User1
> XYZ Company.FFF.MKS|DEF-Engineer|User2
> XYZ Company.FFF.MKS-FCSF|DEF-Engineer|X-User2
>
> And I need to tweak the above file into:
>
> XYZ Company.FFF.MKS
> XYZ Company.FFF.MKS|Designer
> XYZ Company.FFF.MKS|Designer|User1
> XYZ Company.FFF.MKS|Engineer|User2
> XYZ Company.FFF.MKS-FCSF|Engineer|X-User2

awk -v OFS="|" -F "|" 'sub(/.*-/, "", $2)1' inputfile

--
Regards,

---Robert

Report this thread to moderator Post Follow-up to this message
Old Post
Robert Katz
04-18-05 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:20 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.