Sponsored Content
Full Discussion: Adding in Awk
Top Forums Shell Programming and Scripting Adding in Awk Post 302614181 by Franklin52 on Wednesday 28th of March 2012 10:09:49 AM
Old 03-28-2012
Code:
awk 'NR < 5{a[NR%5]=$0; next}{print $0 + a[NR%5+1]}' file


Use nawk or /usr/xpg4/bin/awk on Solaris if you get errors.
This User Gave Thanks to Franklin52 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Adding a new field using sed or awk?

I have a bcp file that contains 10 fields. These fields are separated by a tab. How can I add my name as a new field in the 8th position for every record? I've been playing w/ sed and awk but can't seem to figure this out. (3 Replies)
Discussion started by: sasabune
3 Replies

2. Shell Programming and Scripting

Help with awk adding spaces.

I have a file that contains... elm,mail elm,lisp,composer,cd,ls,cd,ls,cd,ls,zcat,|,tar,-xvf,ls,cd,ls,cd,ls,vi,ls,cd,ls,vi,elm,-f,ls,rm,ls,cd,ls,vi,vi,ls,vi,ls,cd,ls,elm,cd,ls,cd,ls,vi,vi,vi,ls,vi,ls,i,vi,ls,cp,cd,fg,ls,rm,cd,ls,-l,exit elm,mail,biff,elm,biff,elm,elm elm,ls ... (2 Replies)
Discussion started by: Bandit390
2 Replies

3. Shell Programming and Scripting

awk-adding a column to a file

Hello Friends, i used awk to sum up total size of files under a directory (with the help of examples, threads here). ls -l | awk '/^-/ {total += $5} END {printf "%15.0f\n",total}' >> total.txt After each execution of the script total result is appended into a text file: 7010 7794 8890 ... (7 Replies)
Discussion started by: EAGL€
7 Replies

4. UNIX for Dummies Questions & Answers

Adding date when using awk

Hi, I want to print the number of lines of a file along with filename and today's date. Ex: XXX|07-22-2010|8 I am using as wc -c -l file.txt | awk '{print "XXX|",date +"%m-%d-%Y","|",$1}' But this one prints as AAA| 0 | 8 Can anyone please help me on this for printing the date? ... (3 Replies)
Discussion started by: aeroticman
3 Replies

5. Shell Programming and Scripting

Adding column using awk

Hello everyone, I have a file with the following structure: abc xyz 111 222 agf hjhf 787 799 tht yah 878 898 ... ... ... ... ... ... ... ... ... ... ... ... I want to add a column (with a fixed value of 1000) at the end such that it becomes: abc xyz 111 222 1000 agf hjhf 787... (5 Replies)
Discussion started by: ad23
5 Replies

6. Shell Programming and Scripting

Adding A Bump of Numbers with Awk

ok, so i have a bunch of numbers in a file that i'd like to add up. i dont know how to do it. This is how far i've gotten: echo "4 4 5 4 3 4 3 3 4 2 43 3 293 49 23" | sed 's/ / + /g' | awk -F" " I dont want to use the expr command with this as i dont trust it. any advice? thanks (1 Reply)
Discussion started by: SkySmart
1 Replies

7. Shell Programming and Scripting

adding a number with sed or awk.

Hi.. I have this delicate problem..:wall: I have this huge ldif file with entry's like this example below.. And I need to change the following entrys. telephoneNumber: emNotifNumber: billingnumber= BillingNumber: Al these entrys has a number like 012345678 and it needs to add one more... (15 Replies)
Discussion started by: pelama
15 Replies

8. Shell Programming and Scripting

Adding a specified value to a specified column - awk?

Hi everyone! I sometimes need to do some simple arithmetics, like adding a number to a certain column of a file. So I wrote a small function in the .bashrc file, which looks like this shifter() { COL=$1 VAL=$2 FILE=$3 cp $FILE $FILE.shifted awk 'NF==4 {$(( $COL )) = $(( $COL ))... (6 Replies)
Discussion started by: radudownload
6 Replies

9. Shell Programming and Scripting

Awk: adding fields after matching $1

Dear AWK-experts! I did get stuck in the task of combining files after matching fields, so I'm still awkward with learning AWK. There are 2 files: one containing 3 columns with ID, coding status, and score for long noncoding RNAs: file1 (1.txt) (>5000 lines) ... (12 Replies)
Discussion started by: kben
12 Replies

10. Shell Programming and Scripting

Adding tags in between sentences with awk

Hi, I need an awk to modify the following file. It is 2-column tab-separated. Hi PP my VBD name DT is NN . SENT Her PP name VBD is DT the NN same WRT . SENT <s> Hi PP - (6 Replies)
Discussion started by: owwow14
6 Replies
nljust(1)						      General Commands Manual							 nljust(1)

NAME
nljust - justify lines, left or right, for printing SYNOPSIS
digits] seq] just] mode] order] margin] width] ck] [file ...] DESCRIPTION
formats for printing data written in languages with a right-to-left orientation. It is designed to be used with the and the commands (see pr(1) and lp(1)). reads the concatenation of input files (or standard input if none are given) and produces on standard output a right-to-left formatted ver- sion of its input. If appears as an input file name, reads standard input at that point. Use to delimit the end of options. formats input files for all languages that are read from right to left. For languages that have a left-to-right orientation, the command merely copies input files to standard output. Options recognizes the following options: Justify data for all languages, including those having a left-to-right text orientation. By default only right-to-left language data is justified. For all other languages, input files are directly copied to standard output. Select enhanced printer shapes for some Arabic characters. With this option, two-character combinations of laam and alif are replaced by a single character. Triggers ISO 8859-6 interpretation of the data. Processes digits for output as hindi, western, or both. digits can be or both. Use seq as the escape sequence to select the primary character set. This escape sequence is used by languages that have too many characters to be accommodated by ASCII in a single 256-character set. In these cases, the seq escape sequence can be used to select the non-ASCII character set. The escape character itself(0x1b) is not given on the command line. Hewlett-Packard escape sequences are used by default. If just is left justify print lines. If just is right-justify print lines starting from the (designated or default) print width column. The default is right justification. Replace leading spaces with alternative spaces. Some right-to-left character sets have a non-ASCII or alternative space. This option can be useful when filtering out- put (see pr(1)). With right justification, the option causes line numbers to be placed immediately to the right of the tab character. Without the option, right justification causes line numbers to be placed at the print-width column. By default, leading spaces are not replaced by alternative spaces. Indicate mode of any file to be formatted. Mode refers to the text orientation of the file when it was created. If mode is assume Latin mode. If mode is assume non-Latin mode. By default, mode information is obtained from the environment variable. Do not terminate lines containing printable characters with a new-line. By default, print lines are terminated by new-lines. Indicate data order of any file to be formatted. The text orientation of a file can affect the way its data is arranged. If order is assume keyboard order. If order is assume screen order. By default, order information is obtained from the environment variable. Truncate print lines that do not fit the designated or default line length. Print lines are folded (that is, wrapped to next line) by default. Expand input tabs to column positions k+1, 2*k+1, 3*k+1, etc. Tab characters in the input are expanded to the appropriate number of spaces. If k is 0 or is omitted, default tab settings at every eighth position is assumed. If cd (any non-digit character) is given, it is treated as the input tab character. The default for c is the tab character. always expands input tabs. This option provides a way to change the tab character and setting. If this option is specified, at least one of the parameters c or k must be given. Designate a number as the print margin. The print margin is the column where truncation or folding takes place. The print margin determines how many characters appear on a single line and can never exceed the print width. The print margin is relative to the justifica- tion. If the print margin is 80, folding or truncation occurs at column 80 starting from the right during a right jus- tification. Similarly, folding or truncation occurs at column 80 starting from the left during a left justification. By default, the print margin is set to column 80. Designates a number as the print width. The print width is the maximum number of columns in the print line. Print width determines the start of text during a right justification. The larger the print width, the further to the right the text will start. By default, an 80-column print width is used. EXTERNAL INFLUENCES
Environment Variables The environment variable determines the mode and order of the file. The syntax of is [mode][_order]. mode describes the mode of a file where represents Latin mode and represents non-Latin mode. Non-Latin mode is assumed for values other than and order describes the data order of a file where is keyboard and is screen. Keyboard order is assumed for values other than and Mode and order information in can be overridden from the command line. The environment variable determines the direction of a language (left-to-right or right-to-left) and whether context analysis of characters is necessary. The environment variable determines whether a language has alternative numbers. The environment variable determines the language in which messages are displayed. International Code Set Support Single-byte character code sets are supported. EXAMPLES
Right justify on a 132-column printer with a print margin at column 80 (the default): Right justify output of with line numbers on a 132-column printer with a print margin at column 132: WARNINGS
If with line numbers option) is piped to the separator character must be a tab(0x09). It is the user's responsibility to ensure that the environment variable accurately reflects the status of the file. Mode and justification must be consistent. Only non-Latin-mode files can be right justified in a meaningful way. Similarly, only Latin- mode files can be safely left justified. If mode and justification do not match, the results are undefined. If present, alternative numbers always have a left-to-right orientation. The command is HP proprietary, not portable to other vendors' systems, and will not be provided in future HP-UX releases. AUTHOR
was developed by HP. SEE ALSO
forder(1), lp(1), pr(1), strord(3C). nljust(1)
All times are GMT -4. The time now is 08:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy