Sponsored Content
Top Forums Shell Programming and Scripting How to assign variable from a string having blanks in between Post 302086707 by flextronics on Saturday 26th of August 2006 01:51:23 PM
Old 08-26-2006
How to assign variable from a string having blanks in between

Hi All,

I am new to bash scripting. I need your help to removing spaces from a string and assign them to different variables.

Iwant to call script with one command line argument which is file name which containes different attributes their type and different values eg

fdxE1ConfigAdminStatus int 1 2
fdxE1LineType int 1 2 3
.
.
.

Now I want bash script which will take one line every time from this file then in that line it will go till end and puts value in different attributes eg

attr1 = fdxE1ConfigAdminStatus
attr2 = int
attr3 = 1 and 2 [possibly an array]

then it goes to second line and do the same and so on

I started writing script with follwing lines
if [ "$1" = "" ]; then
echo "$0 <attr filename >";
exit;
fi
while read line; do
echo $line;
done

First traversal of loop containes fdxE1ConfigAdminStatus int 1 2
Now I want to remove spaces after fdxE1ConfigAdminStatus, int, 1 and 2 and put them in different attributes eg attr1, attr2 and attr3 and so on.

Could you please help to me to find out a solution.

Thanks in advance
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

read and assign each character from the string to a variable

How... can I read input by a user character by cahracter. And assign each character from the string to a variable? Any help would be greatly appreciated! Thank you! (1 Reply)
Discussion started by: Tek-E
1 Replies

2. Shell Programming and Scripting

how to delete blanks inside a quoted string

Hi I need to update a string inside a file which looks like the following: PX_LIST=" 4119 2390 2294 2776 2897 4099 " Is there a way to get rid of the blanks after the first quote mark and before the last quote mark. This needs to be done ONLY for the string named PX_LIST (there are some... (4 Replies)
Discussion started by: aoussenko
4 Replies

3. Shell Programming and Scripting

How to assign the Pattern Search string as Input Variable

guys, I need to know how to assing pattern matched string as an input command variable. Here it goes' My script is something like this. ./routing.sh <Server> <enable|disable> ## This Script takes an input <Server> variable from this line of the script ## echo $1 | egrep... (1 Reply)
Discussion started by: raghunsi
1 Replies

4. Shell Programming and Scripting

Bash assign string to variable

Hi ,I am trying to assign string to variable ,but it doesn't work Also could you show me different ways to use grep,(I am trying to get the first,second and first column form file,and I am counting the chars) let name=`grep "$id" product | cut -c6-20` (25 Replies)
Discussion started by: lio123
25 Replies

5. Shell Programming and Scripting

need to assign a string to a variable

Hello Experts, In my script i am using the below syntax /usr/bin/head -1 /opt/chumma.txt | /usr/bin/cut -d " " -f3 output of this one is --> Monday I want to store this String in a variable (i.e) j or k... Give me some idea experts. Thanks in advance. (7 Replies)
Discussion started by: natraj005
7 Replies

6. Shell Programming and Scripting

Clearing leading and trailing blanks from a string in C Shell

Does anyone know of a way with C Shell that will work on both Linux and Sun to clear all leading and trailing blanks from a previously specified string? I am using the following code to replace blanks with underscores: set Company = `echo $Company | sed 's/ /_/g but I don't want any... (1 Reply)
Discussion started by: phudgens
1 Replies

7. Shell Programming and Scripting

Problem while assign string (words with tab) to a variable

Hi, I have a String(words with tab space) in a file ->file1.txt 0xxxx 11 test $aa$ 8.43 when i read the file and assign to variable value=$(cat file1.txt) echo $value i get the output without tab spaces. 0xxxx 11 test $aa$ 8.43 How to assign string... (2 Replies)
Discussion started by: nanthagopal
2 Replies

8. Shell Programming and Scripting

Assign a variable the nth character of a string.

I see a millioin ways to do this with echo, but what I wan to do is assign a variable the "nth" character of an incoming parameter to a ksh script. $1 will be "pia" I need to assign the first character to stmttype. (10 Replies)
Discussion started by: klarue
10 Replies

9. Shell Programming and Scripting

Assign large number of blanks to a variable

I want to assign large number of blanks to a variable in Korn shell. If it is a small number it is fine like if I want to assign 3 blanks I would code var=" " But if it is a big number say 100 blanks, what is a better way? Ultimately I will use it in printf statement printf... (3 Replies)
Discussion started by: Soham
3 Replies

10. UNIX for Beginners Questions & Answers

How can I assign awk's variable to shell script's variable?

I have the following script, and I want to assign the output ($10 and $5) from awk to N and L: grdinfo data.grd | awk '{print $10,$5}'| read N L output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Discussion started by: geomarine
8 Replies
XML::Handler::Composer(3)				User Contributed Perl Documentation				 XML::Handler::Composer(3)

NAME
XML::Handler::Composer - Another XML printer/writer/generator SYNOPSIS
use XML::Handler::Composer; my $composer = new XML::Handler::Composer ( [OPTIONS] ); DESCRIPTION
XML::Handler::Composer is similar to XML::Writer, XML::Handler::XMLWriter, XML::Handler::YAWriter etc. in that it generates XML output. This implementation may not be fast and it may not be the best solution for your particular problem, but it has some features that may be missing in the other implementations: o Supports every output encoding that XML::UM supports XML::UM supports every encoding for which there is a mapping file in the XML::Encoding distribution. o Pretty printing When used with XML::Filter::Reindent. o Fine control over which kind of quotes are used See options below. o Supports PerlSAX interface Constructor Options o EndWithNewline (Default: 1) Whether to print a newline at the end of the file (i.e. after the root element) o Newline (Default: undef) If defined, which newline to use for printing. (Note that XML::Parser etc. convert newlines into "x0A".) If undef, newlines will not be converted and XML::Handler::Composer will use "x0A" when printing. A value of " " will convert the internal newlines into the platform specific line separator. See the PreserveWS option in the characters event (below) for finer control over when newline conversion is active. o DocTypeIndent (Default: a Newline and 2 spaces) Newline plus indent that is used to separate lines inside the DTD. o IndentAttList (Default: 8 spaces) Indent used when printing an <!ATTLIST> declaration that has more than one attribute definition, e.g. <!ATTLIST my_elem attr1 CDATA "foo" attr2 CDATA "bar" > o Quote (Default: { XMLDecl => '"', Attr => '"', Entity => '"', SystemLiteral => '"' }) Quote contains a reference to a hash that defines which quoting characters to use when printing XML declarations (XMLDecl), attribute values (Attr), <!ENTITY> values (Entity) and system/public literals (SystemLiteral) as found in <!DOCTYPE>, <!ENTITY> declarations etc. o PrintDefaultAttr (Default: 0) If 1, prints attribute values regardless of whether they are default attribute values (as defined in <!ATTLIST> declarations.) Nor- mally, default attributes are not printed. o Encoding (Default: undef) Defines the output encoding (if specified.) Note that future calls to the xml_decl() handler may override this setting (if they con- tain an Encoding definition.) o EncodeUnmapped (Default: &XML::UM::encode_unmapped_dec) Defines how Unicode characters not found in the mapping file (of the specified encoding) are printed. By default, they are converted to decimal entity references, like '&#123;' Use &XML::UM::encode_unmapped_hex for hexadecimal constants, like '&#xAB;' o Print (Default: sub { print @_ }, which prints to stdout) The subroutine that is used to print the encoded XML output. The default prints the string to stdout. Method: get_compressed_element_suffix ($event) Override this method to support the different styles for printing empty elements in compressed notation, e.g. <p/>, <p></p>, <p />, <p>. The default returns "/>", which results in <p/>. Use " />" for XHTML style elements or ">" for certain HTML style elements. The $event parameter is the hash reference that was received from the start_element() handler. Extra PerlSAX event information XML::Handler::Composer relies on hints from previous SAX filters to format certain parts of the XML. These SAX filters (e.g. XML::Fil- ter::Reindent) pass extra information by adding name/value pairs to the appropriate PerlSAX events (the events themselves are hash refer- ences.) o entity_reference: Parameter => 1 If Parameter is 1, it means that it is a parameter entity reference. A parameter entity is referenced with %ent; instead of &ent; and the entity declaration starts with <!ENTITY % ent ...> instead of <!ENTITY ent ...> NOTE: This should be added to the PerlSAX interface! o start_element/end_element: Compress => 1 If Compress is 1 in both the start_element and end_element event, the element will be printed in compressed form, e.g. <a/> instead of <a></a>. o start_element: PreserveWS => 1 If newline conversion is active (i.e. Newline was defined in the constructor), then newlines will *NOT* be converted in text (character events) within this element. o attlist_decl: First, MoreFollow The First and MoreFollow options can be used to force successive <!ATTLIST> declarations for the same element to be merged, e.g. <!ATTLIST my_elem attr1 CDATA "foo" attr2 CDATA "bar" attr3 CDATA "quux" > In this example, the attlist_decl event for foo should contain (First => 1, MoreFollow => 1) and the event for bar should contain (MoreFollow => 1). The quux event should have no extra info. 'First' indicates that the event is the first of a sequence. 'MoreFollow' indicates that more events will follow in this sequence. If neither option is set by the preceding PerlSAX filter, each attribute definition will be printed as a separate <!ATTLIST> line. CAVEATS
This code is highly experimental! It has not been tested well and the API may change. AUTHOR
Send bug reports, hints, tips, suggestions to Enno Derksen at <enno@att.com>. perl v5.8.0 2000-02-17 XML::Handler::Composer(3)
All times are GMT -4. The time now is 05:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy