07-21-2009
Accessing entire line during "while read"
I am using the time-honored construct "while read field1 field2 field3 ; do" to pull delimited fields from lines of data in a file, but there are a few places within the loop where I need to manipulate the entire, unsplit line of data. Does "while read" keep each entire record/line somewhere prior to its separating the fields -- perhaps in some special variable like $? or $0?
If not, I would either have to use "while read entireLine ; do" and then split up the fields inside the loop with cut or awk, or, use "while read var1 var2 etc. ; do" and paste the separate fields back together where a copy of the whole line is needed, neither of which is very elegant.
Suggestions as to the prettiest, most elegant, or most standard way of having my cake and eating the slices too are most appreciated. --JMF
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi Friends,
Can any of you explain me about the below line of code?
mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`
Im not able to understand, what exactly it is doing :confused:
Any help would be useful for me.
Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
2. Shell Programming and Scripting
Hi,
I need a command in UNIX KSH below is the description...
MAPPING DESCRIPTION ="Test Mapping for the calid inputs" ISVALID ="YES" NAME ="m_test_xml" OBJECTVERSION ="1" VERSIONNUMBER ="1"
unix ksh command to read the DESCRIPTION and write to a file
Test Mapping for the calid inputs... (3 Replies)
Discussion started by: perlamohan
3 Replies
3. Shell Programming and Scripting
Hallo,
i need a Prompting read in my script:
read -p "Enter your command: " command
But i always get this Error:
-p: is not an identifier
When I run these in c-shell i get this error
/usr/bin/read: read: bad option(s)
How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies
4. Shell Programming and Scripting
Hello All,
I am trying to figure out how to use the read command. I have a txt file that has rows looking something like this:
1 2 3 4 5 6 7 8 9
where each number represents an entry of various characters deliminated by tabs.
My goal is to set entries 2-7 as a variable/string that I... (3 Replies)
Discussion started by: Torinator
3 Replies
5. Shell Programming and Scripting
Hi folks,
I want to display the "*" character the entire line. Instead of manually giving "*" multiple times in echo/print command, i want some short cut.
i remember i have came across a straight forward method to display particular character (for example "*" ) for n number of times in unix.... (6 Replies)
Discussion started by: apsprabhu
6 Replies
6. Shell Programming and Scripting
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Discussion started by: shis100
7 Replies
7. Shell Programming and Scripting
Hello everybody,
I'm still slowly treading my way into bash scripting (without any prior programming experience) and hence my code is mostly what some might call "creative" if they meant well :D
I have created a script that serves its purpose but it does so very slowly, since it needs to work... (4 Replies)
Discussion started by: origamisven
4 Replies
8. Programming
Hi,
I have a string like this,
char str ="This, a sample string.\\nThis is the second line, \\n \\n, we will have one blank line";
if I want to use strtok() to seperate the string, which token should I use?
I tried "\n", "\\n", either not working.
peter (1 Reply)
Discussion started by: laopi
1 Replies
9. UNIX for Dummies Questions & Answers
How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address
and column 3 contains “cc” e-mail address to include with same email.
Sample input file, email.txt
Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies
10. Shell Programming and Scripting
Hi everybody,
I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o
My code:
#!/bin/sh
set -e
set -u
export IFS=
optl="Optl"
LOCSTORCLI="/opt/lsi/storcli/storcli"
($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies
LEARN ABOUT DEBIAN
moosex::emulate::class::accessor::fast
MooseX::Emulate::Class::Accessor::Fast(3pm) User Contributed Perl Documentation MooseX::Emulate::Class::Accessor::Fast(3pm)
NAME
MooseX::Emulate::Class::Accessor::Fast - Emulate Class::Accessor::Fast behavior using Moose attributes
SYNOPSYS
package MyClass;
use Moose;
with 'MooseX::Emulate::Class::Accessor::Fast';
#fields with readers and writers
__PACKAGE__->mk_accessors(qw/field1 field2/);
#fields with readers only
__PACKAGE__->mk_ro_accessors(qw/field3 field4/);
#fields with writers only
__PACKAGE__->mk_wo_accessors(qw/field5 field6/);
DESCRIPTION
This module attempts to emulate the behavior of Class::Accessor::Fast as accurately as possible using the Moose attribute system. The
public API of "Class::Accessor::Fast" is wholly supported, but the private methods are not. If you are only using the public methods (as
you should) migration should be a matter of switching your "use base" line to a "with" line.
While I have attempted to emulate the behavior of Class::Accessor::Fast as closely as possible bugs may still be lurking in edge-cases.
BEHAVIOR
Simple documentation is provided here for your convenience, but for more thorough documentation please see Class::Accessor::Fast and
Class::Accessor.
A note about introspection
Please note that, at this time, the "is" flag attribute is not being set. To determine the "reader" and "writer" methods using
introspection in later versions of Class::MOP ( > 0.38) please use the "get_read_method" and "get_write_method" methods in
Class::MOP::Attribute. Example
# with Class::MOP <= 0.38
my $attr = $self->meta->find_attribute_by_name($field_name);
my $reader_method = $attr->reader || $attr->accessor;
my $writer_method = $attr->writer || $attr->accessor;
# with Class::MOP > 0.38
my $attr = $self->meta->find_attribute_by_name($field_name);
my $reader_method = $attr->get_read_method;
my $writer_method = $attr->get_write_method;
METHODS
BUILD $self %args
Change the default Moose class building to emulate the behavior of C::A::F and store arguments in the instance hashref.
mk_accessors @field_names
Create read-write accessors. An attribute named $field_name will be created. The name of the c<reader> and "writer" methods will be
determined by the return value of "accessor_name_for" and "mutator_name_for", which by default return the name passed unchanged. If the
accessor and mutator names are equal the "accessor" attribute will be passes to Moose, otherwise the "reader" and "writer" attributes will
be passed. Please see Class::MOP::Attribute for more information.
mk_ro_accessors @field_names
Create read-only accessors.
mk_ro_accessors @field_names
Create write-only accessors.
follow_best_practices
Preface readers with 'get_' and writers with 'set_'. See original Class::Accessor documentation for more information.
mutator_name_for
accessor_name_for
See original Class::Accessor documentation for more information.
set
See original Class::Accessor documentation for more information.
get
See original Class::Accessor documentation for more information.
meta
See Moose::Meta::Class.
SEE ALSO
Moose, Moose::Meta::Attribute, Class::Accessor, Class::Accessor::Fast, Class::MOP::Attribute, MooseX::Adopt::Class::Accessor::Fast
AUTHORS
Guillermo Roditi (groditi) <groditi@cpan.org>
With contributions from:
Tomas Doran (t0m) <bobtfish@bobtfish.net>
Florian Ragwitz (rafl) <rafl@debian.org>
LICENSE
You may distribute this code under the same terms as Perl itself.
perl v5.10.0 2009-09-15 MooseX::Emulate::Class::Accessor::Fast(3pm)