Sponsored Content
Top Forums Shell Programming and Scripting Adding a specified value to a specified column - awk? Post 302789989 by radudownload on Thursday 4th of April 2013 01:34:52 PM
Old 04-04-2013
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
Code:
 shifter()
 {
 COL=$1
 VAL=$2
 FILE=$3

 cp $FILE $FILE.shifted
 awk 'NF==4 {$(( $COL )) = $(( $COL )) + $VAL}' $FILE.shifted
 }

which should add the number stored in VAL, to the column COL from the FILE file.

Please give me a hint how should I make this work. Thank you! (I'm just a newbie in shell programing)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

problem while adding column values in awk

Hi, I have a file "input.txt" with the following content : 5312,0,,,1,8,141.2,20090727 3714,0,,,1,8,285.87,20090727 5426,0,,,1,8,3.9,20090727 3871,0,,,1,8,30.4,20090727 9071,0,,,1,8,146.2,20090727 5141,0,,,1,8,2.8,20090727 0460,0,,,1,8,-0.1,20090727 7918,0,,,1,8,-0.1,20090727... (3 Replies)
Discussion started by: valokv
3 Replies

2. 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

3. Shell Programming and Scripting

sed/awk-adding numeric to a column

I have a txt file as follows Code: Oct 1 file1 4144 Oct 1 file23 5170 Oct 2 file5 3434 Oct 21 file56 2343 I need to add a new column by marking the right log file from current directory. For example populate like this. Please not in the second columt for "1" it has... (2 Replies)
Discussion started by: gubbu
2 Replies

4. UNIX for Dummies Questions & Answers

Adding a column with the row number using awk

Is there anyway to use awk to add a first column to my data that automatically goes from 1 to n , where n is the numbers of my rows?:confused: (4 Replies)
Discussion started by: cosmologist
4 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. Linux

Adding a prefix to a column using awk/sed commands

Hello, I am a newbie to linux and struggling to find a better way to append a column in a text file. Here is the file i want to modify: It has 8 columns (and thousands of rows). I want to append the first column by adding "chr" infront of the numbers. Some rows have a string in the first... (4 Replies)
Discussion started by: bjorngill
4 Replies

7. Shell Programming and Scripting

Rename a header column by adding another column entry to the header column name URGENT!!

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (4 Replies)
Discussion started by: Vavad
4 Replies

8. UNIX for Dummies Questions & Answers

awk adding counts together from column

Hello Im new treat me nicely, I have a headache :) I have a script that seemed to work now it doesnt anyway, the last part is adding counts of unique items in a csv file eg 05492U34 38 05492U34 47 two columns, (many different values like this in file) i want... (7 Replies)
Discussion started by: aniquebmx
7 Replies

9. UNIX for Dummies Questions & Answers

Des/awk for change format and adding integers in a column of data?

Greetings! I need a quick way to change the format in a table of data Here is an example of the input: 10 72 Value=177 VDB=0.0245 Value4=0,0,171,0 10 274 Value=238 VDB=0.0433 Value4=29,0,205,0 10 312 Value=222 VDB=0.0384 Value4=8,0,190,19 10 540 Value=405 VDB=0.0391 Value4=13,30,153,195... (3 Replies)
Discussion started by: Twinklefingers
3 Replies

10. Shell Programming and Scripting

Adding values of a column based on another column

Hello, I have a data such as this: ENSGALG00000000189 329 G A 4 2 0 ENSGALG00000000189 518 T C 5 1 0 ENSGALG00000000189 1104 G A 5 1 0 ENSGALG00000000187 3687 G T 5 1 0 ENSGALG00000000187 4533 A T 4 2 0 ENSGALG00000000233 5811 T C 4 2 0 ENSGALG00000000233 5998 C A 5 1 0 I want to... (3 Replies)
Discussion started by: Homa
3 Replies
MAKEINFO(1)							   User Commands						       MAKEINFO(1)

NAME
makeinfo - translate Texinfo documents SYNOPSIS
makeinfo [OPTION]... TEXINFO-FILE... DESCRIPTION
Translate Texinfo source documentation to various other formats, by default Info files suitable for reading online with Emacs or standalone GNU Info. General options: --error-limit=NUM quit after NUM errors (default 100). --force preserve output even if errors. --help display this help and exit. --no-validate suppress node cross-reference validation. --no-warn suppress warnings (but not errors). --reference-limit=NUM warn about at most NUM references (default 1000). -v, --verbose explain what is being done. --version display version information and exit. Output format selection (default is to produce Info): --docbook output Docbook XML rather than Info. --html output HTML rather than Info. --xml output Texinfo XML rather than Info. --plaintext output plain text rather than Info. General output options: -E, --macro-expand FILE output macro-expanded source to FILE. ignoring any @setfilename. --no-headers suppress node separators, Node: lines, and menus from Info output (thus producing plain text) or from HTML (thus producing shorter output); also, write to standard output by default. --no-split suppress splitting of Info or HTML output, generate only one output file. --number-sections output chapter and sectioning numbers. -o, --output=FILE output to FILE (directory if split HTML), Options for Info and plain text: --enable-encoding output accented and special characters in Info output based on @documentencoding. --fill-column=NUM break Info lines at NUM characters (default 72). --footnote-style=STYLE output footnotes in Info according to STYLE: `separate' to put them in their own node; `end' to put them at the end of the node in which they are defined (default). --paragraph-indent=VAL indent Info paragraphs by VAL spaces (default 3). If VAL is `none', do not indent; if VAL is `asis', preserve existing indentation. --split-size=NUM split Info files at size NUM (default 300000). Options for HTML: --css-include=FILE include FILE in HTML <style> output; read stdin if FILE is -. Options for XML and Docbook: --output-indent=VAL indent XML elements by VAL spaces (default 2). If VAL is 0, ignorable whitespace is dropped. Input file options: --commands-in-node-names allow @ commands in node names. -D VAR define the variable VAR, as with @set. -I DIR append DIR to the @include search path. -P DIR prepend DIR to the @include search path. -U VAR undefine the variable VAR, as with @clear. Conditional processing in input: --ifdocbook process @ifdocbook and @docbook even if not generating Docbook. --ifhtml process @ifhtml and @html even if not generating HTML. --ifinfo process @ifinfo even if not generating Info. --ifplaintext process @ifplaintext even if not generating plain text. --iftex process @iftex and @tex; implies --no-split. --ifxml process @ifxml and @xml. --no-ifdocbook do not process @ifdocbook and @docbook text. --no-ifhtml do not process @ifhtml and @html text. --no-ifinfo do not process @ifinfo text. --no-ifplaintext do not process @ifplaintext text. --no-iftex do not process @iftex and @tex text. --no-ifxml do not process @ifxml and @xml text. Also, for the --no-ifFORMAT options, do process @ifnotFORMAT text. The defaults for the @if... conditionals depend on the output format: if generating HTML, --ifhtml is on and the others are off; if generating Info, --ifinfo is on and the others are off; if generating plain text, --ifplaintext is on and the others are off; if generating XML, --ifxml is on and the others are off. EXAMPLES
makeinfo foo.texi write Info to foo's @setfilename makeinfo --html foo.texi write HTML to @setfilename makeinfo --xml foo.texi write Texinfo XML to @setfilename makeinfo --docbook foo.texi write DocBook XML to @setfilename makeinfo --no-headers foo.texi write plain text to standard output makeinfo --html --no-headers foo.texi write html without node lines, menus makeinfo --number-sections foo.texi write Info with numbered sections makeinfo --no-split foo.texi write one Info file however big REPORTING BUGS
Email bug reports to bug-texinfo@gnu.org, general questions and discussion to help-texinfo@gnu.org. Texinfo home page: http://www.gnu.org/software/texinfo/ COPYRIGHT
Copyright (C) 2004 Free Software Foundation, Inc. There is NO warranty. You may redistribute this software under the terms of the GNU General Public License. For more information about these matters, see the files named COPYING. SEE ALSO
The full documentation for makeinfo is maintained as a Texinfo manual. If the info and makeinfo programs are properly installed at your site, the command info makeinfo should give you access to the complete manual. makeinfo 4.8 December 2004 MAKEINFO(1)
All times are GMT -4. The time now is 02:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy