Sponsored Content
Full Discussion: awk command to avoid loops
Top Forums Shell Programming and Scripting awk command to avoid loops Post 302361111 by vijayarajvp on Monday 12th of October 2009 09:02:06 AM
Old 10-12-2009
awk command to avoid loops

Hi...
I need a help in using the awk command or any other solution to avoid the usage of loops.

My question is :

I have a input like this :
Code:
 
field1|field2|field3|field4|field5|field6|field7|field8|field9
ex : 4000|testing|scenario|14450|500|320|450|200|100

where the 4th field i.e 14450 is a date field which will be passed to a converter which will automatically convert to the normal date format.

(eg : date_conv(14450) will give output 12/10/2009. )

Now i am looking for a solution which will get the output in the following manner.

o/p format :
Code:
 
4000|testing|scenario|12/10/2009|500|V(hexadecimal value of field6 ) - hexadecimal value of field7) - (field8*10) - field9

Note '-' represents hyphen.

So in my output there will be only 6 fields like :
Code:
 
4000|testing|scenario|12/10/2009|500|field6

where field 6 = v(hexadecimal value of field6 ) - hexadecimal value of field7) - (field8*10) - field9

In My input field6=320 then the hexadecimal value will be 140
if field7=450 then the hexadecimal value will be 1C2.

So my final output will be
Code:
 
4000|testing|scenario|12/10/2009|500|V140-1C2-2000-100

Please help..

Thanks.

Last edited by zaxxon; 10-12-2009 at 11:45 AM.. Reason: code tags!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can I avoid the standard output from kill command

I am sending a kill comand to kill a process inside a SH script but I don`t want the user to notice it so I donīt want the message "1222 killed" to appear. I`ve tried to redirect the standard output to /dev/null 2>&1 and also tried to use "nohup" but none of them was succesfull. Can anyone... (1 Reply)
Discussion started by: pguinal
1 Replies

2. Shell Programming and Scripting

While loops and awk

I am trying to make a script that will replace backslashes in a file, but only if the occurance is a pathname. In the file, there are a lot of regular expressions as well, so I'm trying to preserve the integrity of those regular expressions, but convert Windows relative paths. I'm using bash and... (1 Reply)
Discussion started by: Loriel
1 Replies

3. UNIX for Dummies Questions & Answers

How to avoid historying my command

Dear all, Normally unix automatically record up to 500 the command lines whatever I put in. Does anyone knows how I can avoid this record, in another word, I dont want system remember what I typed in thanks (2 Replies)
Discussion started by: ting123
2 Replies

4. Shell Programming and Scripting

AWK: How to avoid System

How can we avoid the use of system command inside awk program? Is there any alternative way in awk programming for removing files, sorting files and to find the differences between two file without using a system command? Eg: system("rm tempfil006"); How to avoid the use of system in above... (0 Replies)
Discussion started by: sandeep_hi
0 Replies

5. UNIX for Dummies Questions & Answers

how to avoid time command output

Hi, I have 2 queries 1 .when I run some unix command, I am getting the output of "time" at std output (screen) for eg zegrep <pattern> *.v.gz I almost found the reason but not sure, if the no of files matching *.v.gz is more then I am getting the time command output at the... (5 Replies)
Discussion started by: selvaka
5 Replies

6. Shell Programming and Scripting

AWK - Avoid exponential value

I'm using the following command, but how can I avoid printing exponential value (highlighted):- awk ' BEGIN { OFS=FS="|" } { if(NF>4) $10=int(((3.77*$11)/100 + $11)); } { print } ' infile CR|20121022|105|GSM|N|SAN|00122|SAN|75082|6.03929e+06|5819880|5794769|25111... (7 Replies)
Discussion started by: Yoda
7 Replies

7. Shell Programming and Scripting

How to avoid column with a specific name using awk

how can avoid column names that start with Nx_*? file1 name Nx_8977 Nx_988 NN a1 2 0 8 b1 2 0 8 ouput name NN a1 8 b1 8 (5 Replies)
Discussion started by: quincyjones
5 Replies

8. Shell Programming and Scripting

How to avoid error with ln command?

mkdir logs mkdir: Failed to make directory "logs"; File existsTo avoid this error i use the -p argument so it creates a folder only if it is does not exists like you see below. mkdir -p logs In the similar manner i wish to avoid this error with ln command ln -s /tmp/myfolder var ln: cannot... (4 Replies)
Discussion started by: mohtashims
4 Replies

9. UNIX for Beginners Questions & Answers

How to avoid arguments inside Nawk command?

Hi, Here is my command print $2 was meant to select the second column however, it is getting substituted with the second argument that was passed to the script. Can you please tell me how can I resolve this ? (6 Replies)
Discussion started by: mohtashims
6 Replies

10. Shell Programming and Scripting

Avoid running unnecessary repetitive ps command

i have the following code: APIDS=$(echo $(ps -ef | awk -v gpid="${gpid}" '$2 == gpid || $3 == gpid {print $2,$3}') | sed 's~ ~|~g') AllProcs=$(ps -ef | awk -v allpids="${APIDS}" '$2 ~ allpids || $3 ~ allpids {print $0}' | sed '/^$/d') it seems the above... (6 Replies)
Discussion started by: SkySmart
6 Replies
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)
All times are GMT -4. The time now is 04:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy