Sponsored Content
Top Forums Shell Programming and Scripting Using AWK to parse a delimited field Post 302430594 by Fatbob on Friday 18th of June 2010 05:50:13 AM
Old 06-18-2010
Using AWK to parse a delimited field

Hi everyone!

How can I parse a delimited field using AWK?

For example, if I have lastName#firstName or lastName*firstName. I'd like an AWK script that would return lastName and then another that would return firstName? Is this possible?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse comma delimited and optionally quotes dimilited file

Hi, Can you please help me? How to Parse a comma delimited and optionally quotes dimilited file? sample.dat ---------- "I",+2007,"SANDA, 20, MARTIN PLACE","SANDA 20MARTIN" "D",+2008,"RANDA, 22, MARTIN PLACE","RANDA 22MARTIN" Thank you. Ram (8 Replies)
Discussion started by: vramana2003
8 Replies

2. Shell Programming and Scripting

how to parse with awk (using different fields), then group by a field?

When parsing multiple fields in a file using AWK, how do you group by one of the fields and parse by delimiters? to clarify If a file had tom | 223-2222-4444 , randofield ivan | 123-2422-4444 , random filed ... | and , are the delimiters ... How would you group by the social security... (4 Replies)
Discussion started by: Josef_Stalin
4 Replies

3. Shell Programming and Scripting

Use awk or sed to parse delimited string

Hi I am trying to figure out the best way to search a long log file and print out certain information. For example if I had a line in a log file delimited by ampersand first_name=mike&last_name=smith&zip_code=55555&phone=555-5555&state=ma&city=boston and I only wanted to search for and... (3 Replies)
Discussion started by: mstefaniak
3 Replies

4. Shell Programming and Scripting

Parse tab delimited file, check condition and delete row

I am fairly new to programming and trying to resolve this problem. I have the file like this. CHROM POS REF ALT 10_sample.bam 11_sample.bam 12_sample.bam 13_sample.bam 14_sample.bam 15_sample.bam 16_sample.bam tg93 77 T C T T T T T tg93 79 ... (4 Replies)
Discussion started by: empyrean
4 Replies

5. UNIX for Advanced & Expert Users

Parse (delimited string) key-value pairs in a column into separate lines

Hi experts, e.g. i/p data looks like 0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747,9700005405717924,9700005405733788|unidentified,unidentified,unidentified|| o/p data should like - row1: 0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747|unidentified ... (1 Reply)
Discussion started by: sumoka
1 Replies

6. Shell Programming and Scripting

awk : Filter a set of data to parse header line and last field of multiple same match.

Hi Experts, I have a data with multiple entry , I want to filter PKG= & the last column "00060110" or "00088150" in the output file: ############################################################################################### PKG= P8SDB :: VGS = vgP8SOra vgP8SDB1 vgP8S001... (5 Replies)
Discussion started by: rveri
5 Replies

7. Shell Programming and Scripting

awk Parse And Create Multiple Files Based on Field Value

Hello: I am working parsing a large input file which will be broken down into multiples based on the second field in the file, in this case: STORE. The idea is to create each file with the corresponding store number, for example: Report_$STORENUM_$DATETIMESTAMP , and obtaining the... (7 Replies)
Discussion started by: ec012
7 Replies

8. Shell Programming and Scripting

awk to parse field and include the text of 1 pipe in field 4

I am trying to parse the input in awk to include the |gc= in $4 but am not able to. The below is close: awk so far: awk '{sub(/\|]+]++/, ""); print }' input.txt Input chr1 955543 955763 AGRN-6|pr=2|gc=75 0 + chr1 957571 957852 AGRN-7|pr=3|gc=61.2 0 + chr1 970621 ... (7 Replies)
Discussion started by: cmccabe
7 Replies

9. UNIX for Beginners Questions & Answers

awk to parse current and next row in tab-delimited file

Hi there, I would like to use awk to reformat a tab-delimited file containing three columns as follows: Data file: sample 1 173 sample 269 530 sample 687 733 sample 1699 1779 Desired output file: sample 174..265, 531..686, 734..1698 I need the value... (5 Replies)
Discussion started by: emiley
5 Replies

10. Shell Programming and Scripting

awk to parse comma separated field and removing comma in between number and double quotes

Hi Experts, Please support I have below data in file in comma seperated, but 4th column is containing comma in between numbers, bcz of which when i tried to parse the file the column 6th value(5049641141) is being removed from the file and value(222.82) in column 5 becoming value of column6. ... (3 Replies)
Discussion started by: as7951
3 Replies
XML_EZ_Out(7)							 Linux-XML_EZ_Out						     XML_EZ_Out(7)

NAME
XML_EZ_Out - Simple Ada utility package for generating XML output. SYNOPSIS
with McKae.XML.EZ_Out.Generic_Medium; with McKae.XML.EZ_Out.String_Stream; with McKae.XML.EZ_Out.Text_File; package Ezsi is new Mckae.Xml.Ez_Out.Generic_Medium (Output_Medium => File_Type, Put => Put, New_Line => New_Line[, Format => Spread_Indented]); DESCRIPTION
XML_EZ_Out is a small set of packages intended to aid the creation of XML-formatted output from within Ada programs. It basically wraps the tags and data provided to it with XML syntax and writes them to a user-supplied medium. This medium can be any sort of writable entity, such as a file, a memory buffer, or even a communications link, such as a socket. The only functionality required of the medium is that it supply a meaningful "Put" (for writing a string) and "New_Line" procedure. XML_EZ_Out package instantiations are explicitly designed to be made directly visible with the aid of a "use" clause. Declining to use a "use" will make using XML_EZ_Out inordinately verbose and awkward. Generic Specification generic type Output_Medium is limited private; -- Output_Medium is whatever entity is going to received the formatted -- XML output. It can be a file, a stream, a buffer, a socket, whatever. -- All interaction with it takes place solely through the supplied Put and -- New_Line procedures, which are modeled after the Ada.Text_IO procedures. with procedure Put(F : in Output_Medium; S : in String) is <>; -- Procedure writing a string to the instantiating output medium. with procedure New_Line (F : in Output_Medium; Spacing : in Ada.Text_IO.Positive_Count := 1) is <>; -- Procedure writing a line break to the instantiating output medium. Format : Formatting_Options := Spread_Indented; -- Specify whether the XML being written is to be indented, i.e. be -- "prettified". (DEPRECATED, control formatting by setting the -- Current_Format variable available in the package spec.) Max_Element_Nesting : Positive := 200; -- The maximum element nesting depth of an XML document (used to set -- size of tag checking stack). package McKae.XML.EZ_Out.Generic_Medium; Variables Current_Format The indentation format of the XML that is utilized. This can be altered at any time. Available settings are Continuous_Stream and Spread_Indented. (Supersedes deprecated generic parameter Format.) Default_Output_Null_Attributes Boolean indication whether to output an attribute if it has a null value. Package Operations See the Generic_Medium package specification for details of parameters and overloaded variations. Output_XML_Header Procedure to output a standard XML header line, as amended by the supplied arguments. To omit a standard attribute, pass an empty string as its value. Output_Processing_Instruction Add a processing instruction to the XML document. Output_Element Generate an entire element designated with the given tag and containing the provided content and attribute values. Output_Tag Generate an element tag containing zero or more attributes. By default the element is created using the compact, no-end-tag nota- tion; to force generation of an element that has both start and end tags while containing no content, set End_Tag to True. Start_Element Initiate the generation of an XML element with the given tag and zero or more attribute values. End_Element Indicate the completion of the output of an XML element. If a Tag is specified, compare it against the element tag that is cur- rently open, and raise Element_End_Mismatch if the two do not match. If there is no open element, then raise Element_Not_Open. Output_Content Place the text, as is, as the content of the currently open XML element. Output_Content can be called repeatedly, and will simply continue to append the additional content. If there is no open element, raise Element_Not_Open. = Associate an attribute name with a value. There are several overloaded variations of the "=" function for defining attribute name/value pairs. For each, the attribute name, Attr, can be of either the predefined Ada String type or the Unbounded_String type from Ada.Strings.Unbounded. The provided "=" functions accept a Value of a predefined Integer-based, Float-based, String, or Charac- ter type. Errors Element_Not_Open An attempt was made to end, or add content to, an element when there were no open elements awaiting text or completion. Element_End_Mismatch The specified end tag does not match that of the currently open element. Nesting_Too_Deep The number of open, nested elements has exceeded the maximum level that was specified. Consider increasing the value of the Max_Element_Nesting generic parameter. Invalid_Construction An attempt was made to create a malformed document, such as inserting a process instruction into an open element. Auxiliary Packages McKae.XML.EZ_Out.Text_File Mckae.XML.EZ_Out.Generic_Medium pre-instantiated with the predefined Ada.Text_IO.File_Type. Mckae.XML.EZ_Out.String_Stream McKae.XML.EZ_Out.Generic_Medium pre-instantiated with a limited functionality in-memory string buffering package, nested within the Mckae.XML.EZ_Out.String_Stream package as String_Buffering. EXAMPLES
The key facilitator of making XML_EZ_Out usage readable when generating XML documentation is the overloading of a number of variations of the "=" function. By doing this, a simple XML element having no content, such as: <player lastName="Cuddyer" firstName="Michael" team="Twins"/> can be generated as: Output_Tag(F, "player", ("lastName" = "Cuddyer", "firstName" = "Michael", "team" = "Twins")); To simplify the specification of the attributes, variations of "=" are provided. Given these declarations: Batting_Average : Float; At_Bats : Natural; One can directly reference the variables: Output_Tag(F, "stats", ("battingAvg" = Batting_Average, "atBats" = At_Bats)); NOTES
XML_EZ_Out is designed in such a way that instantiations of it are meant to be "used" by the application. When accompanied with a "use" clause, specifying the XML to be produced is very simple and clear. Insisting on using qualified names will make for very obtuse code. Likewise, "named parameter" notation would obscure the complementarity of the Ada and XML, so apply for a waiver from any such style stan- dards. The medium must be open and ready to accept content before invoking any of these XML output subprograms. If the medium raises any exceptions as a result of invoking the supplied Put or New_Line procedures, those exceptions will be passed through to the caller. AUTHOR
Marc A. Criley, McKae Technologies (mc@mckae.com) CAVEATS
XML_EZ_Out does no validation of the XML content it is being asked to output, and it is possible to generate malformed documents. That includes the handling of character encoding. While XML_EZ_Out will claim the document is "UTF-8" or otherwise as set by the application, it is up to the application to ensure that correct content is provided in the strings that are passed to its various subprograms. Used appropriately, though, it can provide a clear and readable means to aid the dynamic generation of XML content by Ada programs. Linux-XML_EZ_Out 2009-12-27 XML_EZ_Out(7)
All times are GMT -4. The time now is 04:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy