awk or a combination of commands to read and calculate nth lines from pattern
Two numerical lines, found by either header line, need to be added
and the total placed in a new-header section. Also the total should
should be rounded or cut to a two decimal anynumber.XX format
with the AB string added on the end.
For example: The numerical lines from headers 2 and 3 are to be added together
and placed in the 4th line of the new-header grouping.
The new line would show 13.24 AB
The data file:
Each grouping contains 4 lines.
The line numbers may change every time the data file is accessed.
The numerical lines may or may not have a type (AB in this example) listed after the number.
The third line in the group, the info line, may or may not be the same.
Data file:
A new section would then be added to the end of the data with no empty line above:
Please become accustomed to supplying sufficient info on and context of your problem. On top of what RavinderSingh13 already said:
- Where (in a larger file) should the new record be placed?
- How should the new info line ("info-xyz" in your sample record) be constructed?
- What be the header name if more than one new headers result?
In the awk below I am trying to remove all lines above and including the pattern Test or Test2. Each block is seperated by a newline and Test2 also appears in the lines to keep but it will always have additional text after it. The Test to remove will not. The awk executed until the || was added... (2 Replies)
Im currently running this command to satisfy a particular task. it works for my purposes. but i want to be able to optimize this string of commands and have it be reduced to 1 or 2 commands, if at all possible:
head -4 datafile 2>/dev/null | cut -c1-400 | wc | awk '{print $2$1$3}' (5 Replies)
I have a file1 like
prt1|als28.1 prt3|als53.1 prt2|als550.1 prt1|bls9.2 prt2|als7.2 prt2|bls0.2
prt2|als872.1 prt1|bls871.1 prt2|als6.2 prt4|als22.1 prt2|bls43.2
I want to create a file2 from this file by comparing all the possible combinations of patterns (prt) assuming prt1... (3 Replies)
Hi,
I am getting crazy after days on looking at it:
Bash in Ubuntu 12.04.1
I want to do this:
pattern="system /path1/file1 file1"
new_pattern=" data /path2/file2 file2"
file to edit: data.db
- I need to search in the file data.db for the nth occurrence of pattern
- pattern must... (14 Replies)
I have an awk script to find the maximum value of the 2nd column of a 2 column datafile, but I need to find the top 5 maximum values of the 2nd column.
Here is the script that works for the maximum value.
awk 'BEGIN { subjectmax=$1 ; max=0} $2 >= max {subjectmax=$1 ; max=$2} END {print... (3 Replies)
I have a file split something like
01/11/2010:
No of users 100
02/11/2010:
No of users 102
03/11/2010:
No of users 99
...
I want to search the file for a particular date and then extract the following line with the date, something like
02/11/2010 No of users 102
I can grep... (6 Replies)
Hi,
I am cutting data from a fixed length test file and then writing out a new record using the echo command, the problem I have is how to stop multiple spaces from being written to the output file as a single space.
Example:
cat filea | while read line
do
field1=`echo $line | cut -c1-2`
... (6 Replies)
I want to show a output like this
Lee Ballancore
PID TTY TIME CMD
31799 pts/3 00:00:00 vim
31866 pts/3 00:00:00 vim
2495 pts/7 00:00:00 vim
8368 pts/0 00:00:00 vim
9544 pts/2 00:00:00 ps
Alistairr Rutherford
PID TTY TIME CMD
8368 pts/0 00:00:00 vim
9544 pts/2 00:00:00 ps
... (3 Replies)
Hello All,
I just wanted to know what are the different ways of using commands in combination.
The most common one which i know is using pipes.
Also grouping is also done like ( ls; date) where output of both the commands is displayed.
Are there any other ways of combining various... (2 Replies)