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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
File conversion gehlnar Shell Programming and Scripting 4 04-17-2009 08:47 AM
File Conversion sridhar_423 Shell Programming and Scripting 2 03-16-2009 04:47 PM
File conversion to ascii mora UNIX for Advanced & Expert Users 4 03-31-2008 01:29 PM
COnversion utility xhtml file to Postscript file dattatray.b SUN Solaris 0 08-25-2005 07:36 AM
file conversion hipo UNIX for Dummies Questions & Answers 1 07-24-2001 10:24 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 04-23-2009
gehlnar gehlnar is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 47
File conversion and awk

Hi Everyone,
I am confused with the output of the input file and I am using below command in script to get the expected output.
Also I want to add another condition using logical AND (&&) in place of $2=="L"{$4=0-$4} as $2=="L" && $3=="L" {$4=0-$4} but I am getting some awk error.
Can someone please advise on this please?


Code:
 
cat $FILENAME |grep "^PL"|tr -d '\015'|sort -k1,2|nawk -F'|' 'BEGIN {OFS="~"}$2=="L"{$4=0-$4};$6=="COM"?$6="SHS":$6="FMT";{arr[$1"~"$5"~"$6]+=$4} END {for (i in arr) {print i,arr[i]}}'>$TEMPFILE
Input File 
============
ISIN|BL|STATUS|QTY|SNAME|CLASS
PLKGHM000017|B|L|85000|KGHM|COM
PLPKO0000016|B|L|310000|PKO S.A.|COM
|B|L|0||
PLKGHM000017|L|L|35000|KGHM|COM
PL0000101937|B|L|100000|DS1110|GOV
|L|L|0||
PLKGHM000017|L|L|40000|KGHM|COM
PLPKO0000016|L|L|290000|PKO S.A.|COM
Present Output
==============
PL0000101937~B~L~100000~DS1110~FMT
PLKGHM000017~B~L~85000~KGHM~SHS
PLKGHM000017~L~L~-35000~KGHM~SHS
PLKGHM000017~L~L~-40000~KGHM~SHS
PLPKO0000016~B~L~310000~PKO S.A.~SHS
PLPKO0000016~L~L~-290000~PKO S.A.~SHS
PLPKO0000016~PKO S.A.~SHS~20000
PL0000101937~DS1110~FMT~100000
PLKGHM000017~KGHM~SHS~10000
Expected Output
==============
PLPKO0000016~PKO S.A.~SHS~20000
PL0000101937~DS1110~FMT~100000
PLKGHM000017~KGHM~SHS~10000

 

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 08:02 AM.


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