Sponsored Content
Top Forums Shell Programming and Scripting Sum value from selected lines script (awk,perl) Post 302360831 by durden_tyler on Saturday 10th of October 2009 04:32:12 PM
Old 10-10-2009
Sorry, but the problem is not clear enough.

Quote:
Originally Posted by paolfili
...
2)Sum the second fields if the difference between first fields is less than 500.
(sliding window)
What's the length of the sliding window ?

- Is it just 2 (1st & 2nd, 2nd & 3rd, 3rd & 4th, ...) ?
- Or is it 3 (1st, 2nd & 3rd; 2nd, 3rd & 4th; ...) ?

Hopefully, it's not a cartesian product, i.e.

1st vs. (2nd, 3rd, 4th, ... , last_row)
2nd vs. (1st, 3rd, 4th, ... , last_row)
3rd vs. (1st, 2nd, 4th, ... , last_row)
...
last_row vs. (1st, 2nd, 3rd, ..., last-1_row)

Quote:
...
1) Becouse 12345678/500 and 12345989/500 both result 24691 sum=4+13
We cannot group the 3rd line so sum=205
And we group the 4th and 5th line so sum=74+22
- Ok, and what do you want to do with the sum ?
- Do you want to display it ? Or do nothing with it (highly unlikely) ?
- If you want to display it, then how ? The total against each row ? Or the total against the first row only ? Or against the second row only ?

Quote:
...
and the 3rd,4th and 5th becouse 12346819 (of the 5th line) - 12346356 (of the 3th line) < 500
This begs the first counter-question. Why compare the 3rd, 4th and 5th (considering that you have been comparing two-at-a-time all this while) ?
So again, what's the length of the sliding window ?

I guess a very simple example of your input file should help here. So, let's say your input file is as follows:

Code:
$
$ cat f1
100 1
200 2
300 3
400 4
500 5
600 6
700 7
$

What do you want your output to look like ?

tyler_durden
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

extracting selected few lines through perl

How can I extract few lines(like 10 to 15, top 10 and last 10) from a file using perl. I do it with sed, head and tail in unix scripting. I am new to perl. Appreciate your help. (2 Replies)
Discussion started by: paruthiveeran
2 Replies

2. Shell Programming and Scripting

Sum of all lines in file without roundup with awk

Hi, I have a file and I want to sum all the numbers in it. Example of the file: 0.6714359 -3842.59553830551 I used your forum (https://www.unix.com/shell-programming-scripting/74293-how-get-sum-all-lines-file.html) and found a script, what worked for me: awk '{a+=$0}END{print a}'... (8 Replies)
Discussion started by: mario8eren
8 Replies

3. Shell Programming and Scripting

shell script(Preferably awk or sed) to print selected number of columns from each row

Hi Experts, The question may look very silly by seeing the title, but please have a look at it clearly. I have a text file where the first 5 columns in each row were supposed to be attributes of a sample(like sample name, number, status etc) and the next 25 columns are parameters on which... (3 Replies)
Discussion started by: ks_reddy
3 Replies

4. Shell Programming and Scripting

Perl script to find particular field and sum it

Hi, I have a file with format a b c d e 1 1 2 2 2 1 2 2 2 3 1 1 1 1 2 1 1 1 1 4 1 1 1 1 6 in column e i want to find all similar fields ( with perl script )and sum it how many are there for instance in format above. 2 - 2 times 4 - 1 time 6 - 1 time what i use is ... (14 Replies)
Discussion started by: Learnerabc
14 Replies

5. Shell Programming and Scripting

trying to print selected fields of selected lines by AWK

I am trying to print 1st, 2nd, 13th and 14th fields of a file of line numbers from 29 to 10029. I dont know how to put this in one code. Currently I am removing the selected lines by awk 'NR==29,NR==10029' File1 > File2 and then doing awk '{print $1, $2, $13, $14}' File2 > File3 Can... (3 Replies)
Discussion started by: ananyob
3 Replies

6. Shell Programming and Scripting

awk script for getting the selected records from a file.

Hello, I have attached one file named file.txt . I have to create a file using the awk script with the records in which 38th position is P and not V . ex it should have 00501 HOLTSVILLE NYP00501 and it should not include 00501 I R S SERVICE CENTER ... (3 Replies)
Discussion started by: sonam273
3 Replies

7. Shell Programming and Scripting

AWK script - extracting min and max values from selected lines

Hi guys! I'm new to scripting and I need to write a script in awk. Here is example of file on which I'm working ATOM 4688 HG1 PRO A 322 18.080 59.680 137.020 1.00 0.00 ATOM 4689 HG2 PRO A 322 18.850 61.220 137.010 1.00 0.00 ATOM 4690 CD ... (18 Replies)
Discussion started by: grincz
18 Replies

8. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

9. UNIX for Dummies Questions & Answers

awk to sum column field from duplicate row/lines

Hello, I am new to Linux environment , I working on Linux script which should send auto email based on the specific condition from log file. Below is the sample log file Name m/c usage abc xxx 10 abc xxx 20 abc xxx 5 xyz ... (6 Replies)
Discussion started by: asjaiswal
6 Replies

10. Shell Programming and Scripting

Shell script count lines and sum numbers from multiple files

I want to count the number of lines, I need this result be a number, and sum the last numeric column, I had done to make this one at time, but I need to make this for a crontab, so, it has to be an script, here is my lines: It counts the number of lines: egrep -i String file_name_201611* |... (5 Replies)
Discussion started by: Elly
5 Replies
jfs_mkfs(8)						     JFS file system creation						       jfs_mkfs(8)

NAME
jfs_mkfs - create a JFS formatted partition SYNOPSIS
jfs_mkfs [options] device [ blocks ] DESCRIPTION
jfs_mkfs is used to create (format) a JFS partition. jfs_mkfs must be run as root. device is the special file name corresponding to the actual device (e.g. /dev/hdb1) on which a JFS file system and/or JFS journal will be created. blocks is the number of blocks to be used for the file system. If omitted, jfs_mkfs automatically figures the file system size. The default block size is 4096. WARNING
jfs_mkfs will destroy all data on the specified device! OPTIONS
-c Check the device for bad blocks before building the file system. -j journal_device Create the external JFS journal on journal_device , create the JFS file system on device , and attach the external journal to the file system. -J journal-options Create the JFS journal on its own device or attach an external JFS journal to the JFS file system using options specified on the command-line. The following journal options are supported: journal_dev Create an external JFS journal on the given device. device=external-journal Attach an existing external JFS journal located on external-journal to the JFS file system that will be created on device. The external journal must already have been created using the command jfs_mkfs -J journal_dev external-journal Attach the external journal to the file system being created by using the command jfs_mkfs -J device=external-journal device Instead of specifying a device name directly, external-journal can also be specified by either LABEL=label or UUID=UUID to locate the external journal by either the volume label or UUID stored in the JFS external log superblock at the start of the journal. Use jfs_tune(8) to display a journal device's volume label and UUID. (See the -l, -L, and -U options of jfs_tune(8).) Only one of the journal_dev or device= options can be given per jfs_mkfs issuance. -L volume_label Set the volume label for the newly formatted device. If -L volume_label is used along with -J journal_device, the volume label of the specified external journal device will be set to volume_label. Otherwise, the volume label of the JFS file system will be set to volume_label. -O Provide case-insensitive support for compatibility with OS/2. -q Quiet execution - do not ask for confirmation before creating the file system. -s log_size Set the log size (in megabytes) of the inline log. If the -s option is not used, the default log size is 0.4% of the aggregate size. -V Print version information and exit (regardless of any other chosen options). EXAMPLES
Format 3rd partition on 2nd hard disk with the volume label "JFS_hdb3": jfs_mkfs -L JFS_hdb3 /dev/hdb3 Format 5th partition on 1st hard disk, verifying each block created: jfs_mkfs -c /dev/hda5 Format 3rd partition on 2nd hard disk as external journal, format 4th partition on 1st hard disk as JFS file system, and attach the exter- nal journal to the file system: jfs_mkfs -j /dev/hdb3 /dev/hda4 REPORTING BUGS
If you find a bug in JFS or jfs_mkfs, please report it via the bug tracking system ("Report Bugs" section) of the JFS project web site: http://jfs.sourceforge.net/ Please send as much pertinent information as possible including any error messages resulting from running jfs_mkfs. SEE ALSO
mkfs(8), jfs_fsck(8), jfs_fscklog(8), jfs_tune(8), jfs_logdump(8), jfs_debugfs(8) AUTHORS
Barry Arndt (barndt@us.ibm.com) William Braswell, Jr. jfs_mkfs is maintained by IBM. See the JFS project web site for more details: http://jfs.sourceforge.net/ March 9, 2005 jfs_mkfs(8)
All times are GMT -4. The time now is 04:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy