Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Sort data by the end of each line using BASH. Post 302466947 by Davinator on Wednesday 27th of October 2010 07:05:25 PM
Old 10-27-2010
Sort data by the end of each line using BASH.

I am trying to sort data within a text document by the information at the end of each line. Please see below for an example:

Code:
<Profile_0 Name="Random name 0" Description="This is the description." Category="System" ProfileFlags.DWD="6" ABCD="{FF350E61-4FFF-4600-BFFF-3B27DD4BA746}"/>
<Profile_1 Name="Random name 1" Description="This is the description. More words are being added." Category="System" ProfileFlags.DWD="6" ABCD="{73F11780-FFFF-420A-B0FC-FFFFF62B2AA0}"/>
<Profile_2 Name="Random name 2" Description="This is the description. Even more words are being added." Category="System" ProfileFlags.DWD="6" ABCD="{4247D9B0-5E89-FFFF-B2C3-FFFF4771BC4C}"/>
<Profile_3 Name="Random name 3" Description="This is the description." Category="System" ProfileFlags.DWD="6" ABCD="{EAA268CD-42F1-4B49-B7A9-608FFFF56748}"/>
<Profile_4 Name="Random name 4 with more words" Description="This is the description." Category="System" ProfileFlags.DWD="6" ABCD="{26BFFFF1-FFFF-4D3C-FFFF-608D23162123}"/>
<Profile_5 Name="Random name 5" Description="Description." Category="System" ProfileFlags.DWD="6" ABCD="{99BFFFF1-FFFF-4D3C-B7A9-608D23162123}"/>

My desired output is to re-order the lines alphabetically based on the information within the ABCD tag.

Code:
<Profile_4 Name="Random name 4 with more words" Description="This is the description." Category="System" ProfileFlags.DWD="6" ABCD="{26BFFFF1-FFFF-4D3C-FFFF-608D23162123}"/>
<Profile_2 Name="Random name 2" Description="This is the description. Even more words are being added." Category="System" ProfileFlags.DWD="6" ABCD="{4247D9B0-5E89-FFFF-B2C3-FFFF4771BC4C}"/>
<Profile_1 Name="Random name 1" Description="This is the description. More words are being added." Category="System" ProfileFlags.DWD="6" ABCD="{73F11780-FFFF-420A-B0FC-FFFFF62B2AA0}"/>
<Profile_5 Name="Random name 5" Description="Description." Category="System" ProfileFlags.DWD="6" ABCD="{99BFFFF1-FFFF-4D3C-B7A9-608D23162123}"/>
<Profile_3 Name="Random name 3" Description="This is the description." Category="System" ProfileFlags.DWD="6" ABCD="{EAA268CD-42F1-4B49-B7A9-608FFFF56748}"/>
<Profile_0 Name="Random name 0" Description="This is the description." Category="System" ProfileFlags.DWD="6" ABCD="{FF350E61-4FFF-4600-BFFF-3B27DD4BA746}"/>

I would like to accomplish this with regular BASH expressions. Any thoughts?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

End of line character in BAsh

I'm trying to match the end of line character in a shell script under bash. What I have done it got is a loop that reads each line of a file into a temp variable and then I get each letter of that variable and do some work on it. One think I want to do it check if the character I checking if the... (1 Reply)
Discussion started by: Rukshan
1 Replies

2. UNIX for Dummies Questions & Answers

add data from command line to end of file

how can I add data from command line to end of file? (3 Replies)
Discussion started by: bryan
3 Replies

3. Shell Programming and Scripting

Sort from start index and end index in line

Hi All, I have a file (FileNames.txt) which contains the following data in it. $ cat FileNames.txt MYFILE17XXX208Sep191307.csv MYFILE19XXX208Sep192124.csv MYFILE20XXX208Sep192418.csv MYFILE22XXX208Sep193234.csv MYFILE21XXX208Sep193018.csv MYFILE24XXX208Sep194053.csv... (5 Replies)
Discussion started by: krish_indus
5 Replies

4. Shell Programming and Scripting

Appending data to the end of a line

I have searched the forms and I can not find info on appending each line of one file to the same line of another file. I know that I can cat one file to another or append the 2nd file to the end of the 1st but not quite sure how to append one line of data to another. For example File 1 has ... (2 Replies)
Discussion started by: scw132
2 Replies

5. Shell Programming and Scripting

BASH: Sort four lines based on first line

I am in the process of sorting an AutoHotkey script's contents so as to make it easier for me to find and view its nearly 200 buzzwords (when I forget which one corresponds with what phrase, which I do now and then). About half to two-thirds of the script's key phrases correspond to locations... (7 Replies)
Discussion started by: SilversleevesX
7 Replies

6. UNIX for Dummies Questions & Answers

vim copy line and paste at the beginning, middle, and end of another line

How would you do vim copy line and paste at the beginning, middle, and end of another line. I know yy copies the whole line and p pastes the whole line, but on its own separate line. Sometimes I would like to copy a line to the beginning, middle, or end of another line. I would think this would be... (3 Replies)
Discussion started by: cokedude
3 Replies

7. Shell Programming and Scripting

To append new data at the end of each line based on substring of last column

Hi guys, I need to append new data at the end of each line of the files. This new data is based on substring (3rd fields) of last column. Input file xxx.csv: U1234|1-5X|orange|1-5X|Act|1-5X|0.1 /sac/orange 12345 0 U5678|1-7X|grape|1-7X|Act|1-7X|0.1 /sac/grape 5678 0... (5 Replies)
Discussion started by: null7
5 Replies

8. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies

9. UNIX for Beginners Questions & Answers

UNIX help adding data to end of a line with a variable

I am trying to add a date variable to the end of each line. This is what I have to start with cat ${DATAPATH}/Participate_Stream${STREAMDATE}.dryak1.csv | grep ^',' | awk '{print $0}' >> ${DATAPATH}/badparticipant.csv This is what I tried $DATE is a variable I have defined. cat... (3 Replies)
Discussion started by: req62861
3 Replies

10. BSD

Keep getting error "-bash: ./.profile_z2: line 52: syntax error: unexpected end of file"

#!/bin/bash #-------------------------------------------------------- # Setup prompt # Author Zeeshan Mirza # Data: 06-08-2017 #-------------------------------------------------------- if then . ./.profile_custom_pre fi umask 022 set -o vi export EDITOR=vi export VISUAL=vi... (3 Replies)
Discussion started by: getzeeshan
3 Replies
LaTeXML::Model(3pm)					User Contributed Perl Documentation				       LaTeXML::Model(3pm)

NAME
"LaTeXML::Model" - represents the Document Model DESCRIPTION
"LaTeXML::Model" encapsulates information about the document model to be used in converting a digested document into XML by the LaTeXML::Document. This information is based on the document schema (eg, DTD, RelaxNG), but is also modified by package modules; thus the model may not be complete until digestion is completed. The kinds of information that is relevant is not only the content model (what each element can contain contain), but also SGML-like information such as whether an element can be implicitly opened or closed, if needed to insert a new element into the document. Currently, only an approximation to the schema is understood and used. For example, we only record that certain elements can appear within another; we don't preserve any information about required order or number of instances. Model Creation "$model = LaTeXML::Model->new(%options);" Creates a new model. The only useful option is "permissive=>1" which ignores any DTD and allows the document to be built without following any particular content model. Document Type "$model->setDocType($rootname,$publicid,$systemid,%namespaces);" Declares the expected rootelement, the public and system ID's of the document type to be used in the final document. The hash %namespaces specifies the namespace prefixes that are expected to be found in the DTD, along with the associated namespace URI. These prefixes may be different from the prefixes used in implementation code (eg. in ltxml files; see RegisterNamespace). The generated document will use the namespaces and prefixes defined here. Namespaces Note that there are two namespace mappings between namespace URIs and prefixes that are relevant to LaTeXML. The `code' mapping is the one used in code implementing packages, and in particular, constructors defined within those packages. The prefix "ltx" is used consistently to refer to LaTeXML's own namespace ("http://dlmf.nist.gov/LaTeXML)". The other mapping, the `document' mapping, is used in the created document; this may be different from the `code' mapping in order to accommodate DTDs, for example, or for use by other applications that expect a rigid namespace mapping. "$model->registerNamespace($prefix,$namespace_url);" Register $prefix to stand for the namespace $namespace_url. This prefix can then be used to create nodes in constructors and Document methods. It will also be recognized in XPath expressions. "$model->getNamespacePrefix($namespace);" Return the prefix to use for the given $namespace. "$model->getNamespace($prefix);" Return the namespace url for the given $prefix. Model queries "$boole = $model->canContain($tag,$childtag);" Returns whether an element with qualified name $tag can contain an element with qualified name $childtag. The tag names #PCDATA, #Document, #Comment and #ProcessingInstruction are specially recognized. "$auto = $model->canContainIndirect($tag,$childtag);" Checks whether an element with qualified name $tag could contain an element with qualified name $childtag, provided an `autoOpen'able element $auto were inserted in $tag. "$boole = $model->canContainSomehow($tag,$childtag);" Returns whether an element with qualified name $tag could contain an element with qualified name $childtag, either directly or indirectly. "$boole = $model->canAutoClose($tag);" Returns whether an element with qualified name $tag is allowed to be closed automatically, if needed. "$boole = $model->canHaveAttribute($tag,$attribute);" Returns whether an element with qualified name $tag is allowed to have an attribute with the given name. Tag Properties "$value = $model->getTagProperty($tag,$property);" Gets the value of the $property associated with the qualified name $tag Known properties are: autoOpen : This asserts that the tag is allowed to be opened automatically if needed to insert some other element. If not set, the tag can only be opened explicitly. autoClose : This asserts that the $tag is allowed to be closed automatically if needed to insert some other element. If not set, the tag can only be closed explicitly. afterOpen : supplies code to be executed whenever an element of this type is opened. It is called with the created node and the responsible digested object as arguments. afterClose : supplies code to be executed whenever an element of this type is closed. It is called with the created node and the responsible digested object as arguments. "$model->setTagProperty($tag,$property,$value);" sets the value of the $property associated with the qualified name $tag to $value. Rewrite Rules "$model->addRewriteRule($mode,@specs);" Install a new rewrite rule with the given @specs to be used in $mode (being either "math" or "text"). See LaTeXML::Rewrite for a description of the specifications. "$model->applyRewrites($document,$node,$until_rule);" Apply all matching rewrite rules to $node in the given document. If $until_rule is define, apply all those rules that were defined before it, otherwise, all rules AUTHOR
Bruce Miller <bruce.miller@nist.gov> COPYRIGHT
Public domain software, produced as part of work done by the United States Government & not subject to copyright in the US. perl v5.10.1 2009-06-11 LaTeXML::Model(3pm)
All times are GMT -4. The time now is 04:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy