Sponsored Content
Top Forums Shell Programming and Scripting [Perl] Split lines into array - variable line items - variable no of lines. Post 302559699 by ejdv on Wednesday 28th of September 2011 05:07:35 AM
Old 09-28-2011
@tyler_durden,

Thanks a lot for this great example.
It should enable me to solve my 'problem'.

---------- Post updated at 11:07 AM ---------- Previous update was at 08:52 AM ----------

@tyler_durden,

I have an additional question.

What if I only want to print Apple and IBM and in that exact order ?
Or for example Oracle, Apple and IBM in this exact order.

I tried to add this:

Quote:
my %OrderedList = (
'Apple' => "1",
'IBM' => "1");

:
:

foreach my $item (@all_comp_products) {
$company = $$item[0];
if ( $OrderedList{$company} ) {
print "Company : $company\n";
print "Products :\n";
foreach my $prod (@{$$item[1]}) {
print " $prod\n";
}
}
}
That results in this:

Quote:
Company : IBM
Products :
DB2
Fortran
ATM
Deep Blue
Company : Apple
Products :
MacBook
iPod
iPad
Pixar
But I need it to be in the order as specified by %OrderedList.

Could you please assist me with this final step ?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

split variable values into array

i have these values inside variable $blah BUNGA TERATAI 3 5055 ITH 1 0 0 0 1 1 JADE TRADER 143W ITH 4 0 0 0 4 4 MOL SPLENDOR 0307A ITH 3 0 0 0 3 3 so how do I split them into array with the... (4 Replies)
Discussion started by: finalight
4 Replies

2. Shell Programming and Scripting

Join in a single line variable number of lines

Hi all, I have a file with little blocks beginning with a number 761XXXXXX, and 0, 1, 2 or 3 lines below of it beginning with STUS as follow: 761625820 STUS ACTIVE 16778294 STUS NOT ACTIVE 761157389 STUS ACTIVE 16778294 761554921 STUS ACTIVE 16778294 STUS NOT ACTIVE STUS ACTIVE OP... (4 Replies)
Discussion started by: cgkmal
4 Replies

3. Shell Programming and Scripting

split single line into two line or three lines

Dear All, I want to split single line into two line or three lines wherever “|” separated values comes using Input line test,DEMTEMPUT20100404010012,,,,,,,,|0070086|0070087, output shoule be test,DEMTEMPUT20100404010012,,,,,,,,0070086, test,DEMTEMPUT20100404010012,,,,,,,,0070087, (14 Replies)
Discussion started by: arvindng
14 Replies

4. Shell Programming and Scripting

Split line in to 3 lines

Hi, I have a file which contains 1000's of lines. Each line is a log which is pretty long. So i want to split the each line based on 3 category. 1> Date 2><REQUEST> 3><RESPONSE> So below is the example of a line. 2010-11-16 00:45:12,314<REQUEST><VALIDATION-ERROR><soapenv:Envelope... (16 Replies)
Discussion started by: raghunsi
16 Replies

5. Shell Programming and Scripting

Delete lines in an array Using perl

im having an array @check which contains text ..i want to open the array and i have to delete lines starting from a word called "check1" till "check2" for eg:- check1 Use descriptive titles when posting. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt".... (0 Replies)
Discussion started by: rajkrishna89
0 Replies

6. Shell Programming and Scripting

Need to remove first 6 lines and last line in a array ---- perl scripting

Hi I have stored a command output in an array like below @a = `xyz`; actually xyz comnad will give the output like this tracker date xxxxxxx xxxxxxx --------------------- 1 a 2 b ---------------------- i have stored the "xyz" output to an... (3 Replies)
Discussion started by: siva kumar
3 Replies

7. Shell Programming and Scripting

How to get lines having a variable in perl?

Hi, This might be simple question. But i couldn't find the answer. #$ra is having a value which i have got from some other file I want the first occurrence of the line having the value that is in variable "$ra" This is what i have tried. while ( $iop = <TST>) { if($iop =~ /$ra/) { ... (6 Replies)
Discussion started by: twistedpair
6 Replies

8. Shell Programming and Scripting

How do I split a single-line input into five lines?

Example input: John:Shepherd:770-767-4040:U.S.A:New York Mo Jo:Jo Jo: 666-666-6666:U.S.A:Townsville Expected Output: First Name: John Last Name: Shepherd Phone Number: 770-767-4040 Country: U.S.A State: New York First Name: Mo Jo Last Name: Jo Jo Phone Number: 666-666-6666... (10 Replies)
Discussion started by: Camrikron
10 Replies

9. Shell Programming and Scripting

Split a line into multiple lines based on delimeters

Hi, I need help to split any lines that contain ; or , input.txtAc020 Not a good chemical process AC030 many has failed, 3 still maintained AC040 Putative; epithelial cells AC050 Predicted binding activity AC060 rodC Putative; upregulated in 48;h biofilm vs planktonic The output... (8 Replies)
Discussion started by: redse171
8 Replies

10. Shell Programming and Scripting

Search for a pattern in a file and split the line into two lines

Hi All, Greetings everyone !!! I have a file which has many lines, out of which one line is as below. I need to search for pattern "varchar(30) Select" and if exists, then split the line as below. I am trying to achieve this in ksh. Can anyone help me on this. (8 Replies)
Discussion started by: Pradhikshan
8 Replies
OGONKIFY(1)						      General Commands Manual						       OGONKIFY(1)

NAME
ogonkify - international support for PostScript SYNOPSIS
ogonkify [-p procset] [-e encoding] [-r Old=New] [-a] [-c] [-h] [-t] [-A] [-C] [-H] [-T] [-AT] [-CT] [-ATH] [-CTH] [-E] [-N] [-M] [-mp] [-SO] [-AX] [-F] [-RS] [--] file ... DESCRIPTION
ogonkify does various munging of PostScript files related to printing in different languages. Its main use is to filter the output of Net- scape, Mosaic and other programs in order to print in languages that don't use the standard Western-European encoding (ISO 8859-1). SUMMARY USAGE
Installation instructions are provided in the file INSTALL. Assuming the installation has been correctly completed, save the PostScript output of Netscape or Mosaic to a file, say output.ps. Then print it using % ogonkify -AT -N output.ps | lpr in the case of Netscape, or % ogonkify -AT -M output.ps | lpr in the case of Mosaic. You may want to change the -AT option to -CT in order to use a high quality Courier font from IBM (at the price of slower printing). An alternative way to print from Netscape is to set the printing command in the printing dialog box to: ogonkify -AT -N | lpr For more details, see the USAGE section below. OPTIONS
-p Includes the specified procset in the output file. -e Set the encoding of the output. Defaults to L2 (ISO 8859-2, a.k.a. ISO Latin-2). Other possible values are L1 (ISO 8859-1, a.k.a. ISO Latin-1), L3 (ISO 8859-3, a.k.a. ISO Latin-3), L4 (ISO 8859-4, a.k.a. ISO Latin-4), L5 (ISO 8859-9, a.k.a. ISO Latin-5), L6 (ISO 8859-10, a.k.a. ISO Latin-6), L7 (ISO 8859-13, a.k.a. ISO Latin-7), L9 (ISO 8859-15, a.k.a. ISO Latin-9), CP1250 (Microsoft Code Page 1250, a.k.a. CeP), ibmpc (Original IBM-PC encoding), mac (Apple Macintosh encoding) and hp (HP Roman Encoding). -r Use the font New in place of Old. Will lead to ugly or unreadable output when the metrics mismatch. -a Do the right font remappings for using Courier-Ogonki in place of Courier (the a stands for Adobe Courier). This avoids downloading any fonts to the printer. -c Do the right font remappings for using IBM Courier in place of Adobe Courier. -t Do the right font remappings for using Times-Roman-Ogonki in place of Times-Roman. -h Do the right font remappings for using Helvetica-Ogonki in place of Helvetica. -A Like -a but also downloads the Courier-Ogonki fonts. -C Like -c, but also downloads the IBM Courier fonts. -H Like -h, but also downloads the Helvetica-xxx-Ogonki fonts. -T Like -t, but also downloads the Times-xxx-Ogonki fonts. -CT Equivalent to -C -T. -CTH Equivalent to -C -T -H. -E Add the Euro currency sign to all standard fonts (use with -e L9). -N Do Netscape processing. -M Do Mosaic processing. -mp Do mp processing. Will not work with the -A option (use -C instead). -SO Do StarOffice processing. -AX Do ApplixWare processing. -F Do XFig processing. -RS Recode standard fonts. This is likely to work with applications that leave fonts in AdobeStandardEncoding, typically applications that do not even support printing even of characters. -- End options. USAGE
Let us assume that you want to print a WWW page encoded in ISO Latin-2. Netscape stubbornly insists on printing it as ISO Latin-1. By using the File->Print command, have Netscape send the output to a file, say alamakota.ps. As ogonkify is configured for ISO Latin-2 by default, passing it the PostScript generated by Netscape will correct the encoding of the fonts. It is enough to do: % ogonkify -N <alamakota.ps | lpr However, most printers do not have fonts with the needed characters installed; synthesized fonts will be downloaded and used instead of Courier and Times-Roman with -AT, and a very good Courier font from IBM will be used with: -CT. The command will therefore typically be: % ogonkify -N -AT <alamakota.ps | lpr or eventually % ogonkify -N -CT <alamakota.ps | lpr Typical usage with other programs is: % ogonkify -M -AT <alamakota.ps | lpr % ogonkify -mp -AT <alamakota.ps | lpr % ogonkify -SO -AT <alamakota.ps | lpr % ogonkify -AX -ATH <alamakota.ps | lpr % ogonkify -XF -ATH <alamakota.ps | lpr BUGS
Characters with an `ogonek' should be constructed differently (for instance, the `ogonek' used with an `a' should be differently shaped than the one used with an `e'.) It would be better to patch the programs we have the sources to than to post-process the produced PostScript. The program is written in Perl. NOTES
In order to view the output PostScript with Ghostscript, you might need to run gs with the flag -dNOPLATFONTS, and ghostview with the flag -arguments -dNOPLATFONTS. Netscape, IBM, Adobe, PostScript, StarOffice, ApplixWare and possibly others are registered trademarks. THANKS
Much of the composite character data have been provided by Primoz Peterlin, H. Turgut Uyar, Ricardas Cepas, Kristof Petrovay and Jan Prikryl. Jacek Pliszka provided the support for StarOffice. Andrzej Baginski provided the support for ApplixWare. Markku Rossi wrote genscript and provided many useful encoding vectors with the distribution. Throughout writing the Postscript code, I used the ghostscript interpreter, by Peter Deutsch. Larry Wall wrote perl, the syntax and semantics of which are a never ending source of puzzlement. AUTHOR
Juliusz Chroboczek <jec@dcs.ed.ac.uk>, with help from loads of people. McKornik Jr. 14 May 1999 OGONKIFY(1)
All times are GMT -4. The time now is 03:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy