Sponsored Content
Top Forums Shell Programming and Scripting Scripting Help needed with a text file. Post 302678457 by Chirel on Saturday 28th of July 2012 03:36:10 AM
Old 07-28-2012
Hi,

Alister you are right, even if this solve the problem it's not user friendly, so here is the readable version Smilie

First take only company name and the A/B status and we sort them

Code:
# awk '/^[0-9]/ { print $2,$3}' input-file | sort > sorted-file

Then we process the sorted-file by counting duplicates and re-arrange output

Code:
# uniq -c sorted-file | awk -f doit.awk
Company    Count   A   B
aaa            4   2   2
abc            2   1   1
bbb            1   1   0
esd            5   1   4
tre            2   0   2
wes            5   1   4

here is the content of the file doit.awk :
Code:
BEGIN { 
  print "Company    Count   A   B"
}

{
  if (comp && comp != $2) {
    printf("%-10s %5d %3d %3d\n",comp,a["A"]+a["B"],a["A"],a["B"]);
    comp="";
    a["A"]=a["B"]=0;
  }
  comp=$2;
  a[$3]=$1;
}

END {
  if (comp) printf("%-10s %5d %3d %3d\n",comp,a["A"]+a["B"],a["A"],a["B"]);
}

This User Gave Thanks to Chirel For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Urgent help needed to delete some text without opening the file in unix

Hi To delete some text in 2 files in line1 ( not complete line) in unix without opening the files. For example: source file is like this <?xml version="1.0"... (5 Replies)
Discussion started by: pyaranoid
5 Replies

2. Shell Programming and Scripting

Help needed in extracting text present between two headers in .txt file

Hi All, Please help me out in fllowing problem. I have text file which contains the data in following format. Contents of file.txt are setregid02 Test that setregid() fails and sets the proper errno values when a non-root user attemps to change the real or effective... (2 Replies)
Discussion started by: varshit
2 Replies

3. Shell Programming and Scripting

Scripting change of text in another file

Hello, I am pretty new to UNIX/bash scripting, so this question may seem obvious. My experience is simply stringing commands together in a script, maybe doing some if/then testing and such, so I haven't gotten into anything too heavy... I have a shell script that I use as a template to create... (7 Replies)
Discussion started by: vwgtiturbo
7 Replies

4. Shell Programming and Scripting

search needed part in text file (awk?)

Hello! I have text file: From aaa@bbb Fri Jun 1 10:04:29 2010 --____OSPHWOJQGRPHNTTXKYGR____ Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline My code '234565'. ... (2 Replies)
Discussion started by: candyme
2 Replies

5. Shell Programming and Scripting

shell or perl script needed for ldif file to text file conversion

This is the ldf file dn: sdcsmsisdn=1000000049,sdcsDatabase=subscriberCache,dc=example,dc=com objectClass: sdcsSubscriber objectClass: top postalCode: 29600 sdcsServiceLevel: 10 sdcsCustomerType: 14 givenName: Adelia sdcsBlackListAll: FALSE sdcsOwnerType: T-Mobile sn: Actionteam... (1 Reply)
Discussion started by: LinuxFriend
1 Replies

6. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

7. Shell Programming and Scripting

Needed shell script to append desired text to each line in a file

Hi, I had generated a report in my tool as followsoutput.txt 43.35 9 i needed the script to generate a new file like below i want to append the text to each of these lines of my filenewoutputfile.txt should be Total Amount : 43.35 Record Count:9 Regards, Vasa Saikumar. ... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

8. Shell Programming and Scripting

Help needed editing text file using the terminal

Hi, I have text file with the header like this tracking_id condition replicate FPKM XLOC_000001 alpha 1 10.3199 XLOC_000001 alpha 0 10.3686 XLOC_000001 alpha 2 15.5619 ... With the first column being genes, the second being the condition, the third... (5 Replies)
Discussion started by: 4galaxy7
5 Replies

9. Shell Programming and Scripting

FTP a file using Shell Scripting (Help needed)

the requirements is to have a linux script which connects to a windows machine using ftp command and check for a flag file if found copy a .csv file into current machine. (3 Replies)
Discussion started by: tradingspecial
3 Replies

10. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies
lt-comp(1)																lt-comp(1)

NAME
lt-comp - This application is part of the lexical processing modules and tools ( lttoolbox ) This tool is part of the apertium machine translation architecture: http://www.apertium.org. SYNOPSIS
lt-comp [ lr | rl ] dictionary_file output_file DESCRIPTION
lt-comp Is the application responsible of compiling dictionaries used by lt-proc in Apertium into a compact and efficient representation (a class of finite-state transducers called augmented letter transducers). OPTIONS
lr The resulting transducer will process dictionary entries left-to-right. rl The resulting transducer will process dictionary entries right-to-left. FILES
dictionary_file The input dictionary. output_file The compiled dictionary (a finite state transducer). SEE ALSO
lt-proc(1), lt-expand(1), apertium-tagger(1), apertium-translator(1). BUGS
Lots of...lurking in the dark and waiting for you! AUTHOR
(c) 2005,2006 Universitat d'Alacant / Universidad de Alicante. All rights reserved. 2006-03-08 lt-comp(1)
All times are GMT -4. The time now is 01:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy