Sponsored Content
Full Discussion: Control-break"ish" in awk
Top Forums UNIX for Dummies Questions & Answers Control-break"ish" in awk Post 302932067 by RavinderSingh13 on Monday 19th of January 2015 01:38:54 AM
Old 01-19-2015
Hello beca123456,

As per your request each 1st field with respect to 2nd field should be less than 4, so I have taken field 2 as index and added all it's first fields(Assuming as per given data like there will be only 2 fields with values and one will be for ref) and if sum is less than 8 means we are good to add * at end else don't do anything. Now about your query to give Input_file 2 times, in awk we can read multiple files(same like we can multiple arguments to a script). It will read files one by one. Here I want to mention I have put condition FNR==NR this condition will be true only when first file will be read as FNR value will be reset to one each time it goes to read next file but NR value will be keep on increasing even file name is changed, so it will like as follows.
Code:
awk '{print FNR ":" NR}' Input_file Input_file
1:1
2:2
3:3
4:4
5:5
6:6
1:7
2:8
3:9
4:10
5:11
6:12

Notice the highlighted ones for FNR values. I hope this helps, if you have any query kindly do let me know, will try to solve.


Thanks,
R. Singh
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

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

help for saving vertical datas to horizontal with "awk" or "cut"

hi, i have a file having datas like that ./a.txt 12344 12345 12346 12347 ..... ..... ... i want to save this datas to another file like that ./b.txt 12344 12345 12346 12347 ... ... ... i think awk can make this but how? :) waiting for ur help. (3 Replies)
Discussion started by: mercury
3 Replies

3. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

4. Shell Programming and Scripting

"last" in perl vs "break" elsewhere

Is there a functional difference between the two statements? (4 Replies)
Discussion started by: thmnetwork
4 Replies

5. Shell Programming and Scripting

Simplify Bash Script Using "sed" Or "awk"

Input file: 2 aux003.net3.com error12 6 awn0117.net1.com error13 84 aux008 error14 29 aux001.ha.ux.isd.com error12 209 aux002.vm.ux.isd.com error34 21 alx0027.vm.net2.com error12 227 dux001.net5.com error123 22 us008.dot.net2.com error121 13 us009.net2.com error129Expected Output: 2... (4 Replies)
Discussion started by: sQew
4 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

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

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

8. Tips and Tutorials

How to do a "Control Break" (Algorithm)

A vast amount of problems asked in "Shell Programming an Scripting" can be traced back to be an application of a basic algorithm called a Control Break. Every programmer - and script writers are programmers nonetheless - should immediately recognize problems of this sort and know how to deal with... (1 Reply)
Discussion started by: bakunin
1 Replies

9. UNIX for Dummies Questions & Answers

Find a string across line break (because of "segmentation fault core dumped")

Hi, thanks to a precedent post, and thanks to the reply of derekludwig of the forum, I have convert my first awk command as : test.txt is : AAAAAGHIJKLAjKMEFJKLjklABCDJkLEFGHIJKL awk -f findstring.awk test.txt > textreturn.txtfindstring.awk is : BEGIN{ SLENGTH = 3 } { ... (3 Replies)
Discussion started by: thewizarde6
3 Replies

10. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
Flow(3pm)						User Contributed Perl Documentation						 Flow(3pm)

NAME
Data::Flow - Perl extension for simple-minded recipe-controlled build of data. SYNOPSIS
use Data::Flow; $recipes = { path => { default => './MANIFEST'}, contents => { prerequisites => ['path', 'x'] , process => sub { my $data = shift; $data->{ shift() } = `cat $data->{'path'}` x $data->{'x'}; } }, }; $request = new Data::Flow $recipes; $request->set( x => 1); print $request->get('contents'); tie %request, Data::Flow, $recipes; $request{x} = 1; print $request{contents}; DESCRIPTION
The module Data::Flow provides its services via objects. The objects may be obtained by the usual $request = new Data::Flow $recipes; paradigm. The argument $recipes is a hash reference, which provides the rules for request processing. The objects support three methods, set(), get(), aget(), and already_set(). The first one is used to provide input data for processing, the second one to obtain the output. The third one to obtain a reference to an array with results of repeated get(), and the last one to query whether a field is already known. The unit of requested information is a field. The method set() takes a pair "field => value", the methods get() and already_set() take one argument: the "field", and the method aget() takes multiple fields. Every object is created without any fields filled, but it knows how to construct fields basing on other fields or some global into. This knowledge is provided in the argument $recipe of the new() function. This is a reference to a hash, keyed by fields. The values of this hash are hash references themselves, which describe how to acquire the field which is the corresponding key of the initial hash. The internal hashes may have the following keys: "default" describes the default value for the key, if none is provided by set(). The value becomes the value of the field of the object. No additional processing is performed. Example: default => $Config{installdir} "prerequisites" gives the fields which are needed for the construction of the given field. The corresponding value is an array references. The array contains the required fields. If "defaults" did not satisfy the request for a field, but "$recipe->{field}{prerequisites}" exists, the required fields are build before any further processing is done. Example: prerequisites => [ qw(prefix arch) ] "process" contains the rule to build the field. The value is a reference to a subroutine taking 2 arguments: the reference to a hash with all the fields which have been set, and the name of the required field. It is up to the subroutine to actually fill the corresponding field of the hash, an error condition is raised if it did not. Example: process => sub { my $data = shift; $data->{time} = localtime(time) } } "oo_process" contains the rule to build the field. The value is a reference to a subroutine taking 2 arguments: the object $request, and the name of the required field. It is up to the subroutine to actually fill the corresponding field of $request, an error condition is raised if it did not. Example: oo_process => sub { my $data = shift; $data->set( time => localtime(time) ) } "output" the corresponing value has the same meaning as for "process", but the return value of the subroutine is used as the value of the field. Example: output => sub { localtime(time) } "oo_output" the corresponing value has the same meaning as for "process", but the return value of the method is used as the value of the field. Example: output => sub { my $self = shift; $self->get('r') . localtime(time) } "filter" contains the rule to build the field basing on other fields. The value is a reference to an array. The first element of the array is a reference to a subroutine, the rest contains names of the fields. When the subroutine is called, the arguments are the values of fields of the object $request which appear in the array (in the same order). The return value of the subroutine is used as the value of the field. Example: filter => [ sub { shift + shift }, 'first_half', 'second_half' ] Note that the mentioned field will be automatically marked as prerequisites. "self_filter" is similar to "filter", but an extra argument, the object itself, is put in front of the list of arguments. Example: self_filter => [ sub { my ($self, $first_half = (shift, shift); $first_half *= -$self->get('total')*100 if $first_half < 0; # negative means percentage $first_half + shift }, 'first_half', 'second_half' ] "class_filter" is similar to "filter", but the first argument is the name of the method to call, second one is the name of the package to use for the method invocation. The rest contains names of field to provide as method arguments. Example: class_filter => [ 'new', 'FileHandle', 'filename' ] "method_filter" is similar to "class_filter", but the second argument is the name of the field which is used to call the method upon. Example: method_filter => [ 'show', 'widget_name', 'current_display' ] Tied interface The access to the same functionality is available via tied hash interface. AUTHOR
Ilya Zakharevich, cpan@ilyaz.org, with multiple additions from Terrence Monroe Brannon and Radoslav Nedyalkov. SEE ALSO
perl(1), make(1). perl v5.10.0 2008-05-11 Flow(3pm)
All times are GMT -4. The time now is 07:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy