How to add one to each row values and keep it after the value in the column?


 
Thread Tools Search this Thread
Top Forums Programming How to add one to each row values and keep it after the value in the column?
# 1  
Old 12-02-2015
How to add one to each row values and keep it after the value in the column?

Dear Folks

Hello

I have a column of numbers, say:
Code:
26
79
68

I want to add one to each row value and get this desire column:
Code:
26 
27
79
80
68
69

Thanks in advance

Saj

Last edited by sajmar; 12-02-2015 at 12:30 PM..
# 2  
Old 12-02-2015
Any attempts/thoughts/ideas from your side?

---------- Post updated at 18:15 ---------- Previous update was at 18:13 ----------

Howsoever, try
Code:
awk '{print $1; print $1+1}' file
26
27
79
80
68
69

# 3  
Old 12-02-2015
Code:
perl -pe '$_.=$_+1 ."\n"' sajmar.file
26
27
79
80
68
69

# 4  
Old 12-02-2015
Quote:
Originally Posted by sajmar
Dear Folks

Hello

I have a column of numbers, say:
Code:
26
79
68

I want to add one to each row value and get this desire column:
Code:
26 
27
79
80
68
69

Thanks in advance
Saj
Hello Saj,

Following may help you too in same.
1st code:
Code:
awk '{for(i=1;i<=NF;i++){print $i ORS $i+1}}' FS="\n" RS=""  Input_file

2nd code:
Code:
awk '{print $0 ORS $0+1}' Input_file

Output will be as follows in above both codes.
Code:
26
27
79
80
68
69

NOTE: These solutions are based on your shown inputs.

Thanks,
R. Singh
# 5  
Old 12-02-2015
Code:
awk '1;{print $1+1}' sajmar.file
26
27
79
80
68
69

# 6  
Old 12-02-2015
Thanks to all of the folks that gave their suggestions.
# 7  
Old 12-02-2015
Code:
awk '1; {$1++} 1' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unique values in a row sum the next column in UNIX

Hi would like to ask you guys any advise regarding my problem I have this kind of data file.txt 111111111,20 111111111,50 222222222,70 333333333,40 444444444,10 444444444,20 I need to get this file1.txt 111111111,70 222222222,70 333333333,40 444444444,30 using this code I can... (6 Replies)
Discussion started by: reks
6 Replies

2. Shell Programming and Scripting

Parsing Column Values in Row

Hi , I have been trying to write a awk script which will have the following Output 1. Append the last Characters of the lines matching pattern xxxxxxxxx & then a space & then Append the last Characters of the lines matching pattern yyyyyyyyy 2. the process will continue till end of file &... (10 Replies)
Discussion started by: newageBATMAN
10 Replies

3. Shell Programming and Scripting

Move values from column to row

Hello guys. Please can you help me with this.. Thanks in advance:b: Input file 2134 6371 N 2150 6371 M 2166 6371 S 2138 6417 N 2154 6417 M 2170 6417 S 2157 6603 N 2173 6603 M 2189 6603 S desired uotput 6371 2134N 2150M 2166S 6417 2138N 2154M 2170S... (2 Replies)
Discussion started by: jiam912
2 Replies

4. Shell Programming and Scripting

Print every 5 4th column values as separate row with different first column

Hi, I have the following file, chr1 100 200 20 chr1 201 300 22 chr1 220 345 23 chr1 230 456 33.5 chr1 243 567 90 chr1 345 600 20 chr1 430 619 21.78 chr1 870 910 112.3 chr1 914 920 12 chr1 930 999 13 My output would be peak1 20 22 23 33.5 90 peak2 20 21.78 112.3 12 13 Here the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

Deleting row if all column values are a particular string

Hello, I have a very large file for which I would like to remove all rows for which the value of columns 2-5 is zero. For instance I would like this file: contig1, 0, 0, 0, 0 contig2, 1, 3, 5, 0 contig3, 0, 0, 0, 0 contig4, 0, 5, 6, 7 To become this file: contig2, 1, 3, 5,0 ... (17 Replies)
Discussion started by: mouchkam
17 Replies

6. Shell Programming and Scripting

Arrange values of a column in row

HI, I need to arrange values of a colum in row. e.g. input file : Alpha<>123 AAAA<>6754 Beta<>456 BBBB<>63784 CCC<>783 Gama<>789 Alpha<>555 AAAA<>6754 BBBB<>63784 Beta<>666 CCC<>783 Gama<>888 (9 Replies)
Discussion started by: The_Archer
9 Replies

7. Shell Programming and Scripting

Find and replace duplicate column values in a row

I have file which as 12 columns and values like this 1,2,3,4,5 a,b,c,d,e b,c,a,e,f a,b,e,a,h if you see the first column has duplicate values, I need to identify (print it to console) the duplicate value (which is 'a') and also remove duplicate values like below. I could be in two... (5 Replies)
Discussion started by: nuthalapati
5 Replies

8. Shell Programming and Scripting

Converting values in a ROW to COLUMN

Hi All, I needd to convert values in a row to a column. eg: Input is as: value1,value2,value3,value4,.........,value N Required Output: Value1 Value2 Value3 . . . Value N Please help.... (3 Replies)
Discussion started by: sambaman
3 Replies

9. Shell Programming and Scripting

Convert column values into row

hi, I have a requirement where in I read the values from a file using awk. The resulting data should be converted into row format from column format. For ex: My log file login.lst contains the following SERVER1 DB1 SERVER2 DB2 SERVER3 DB3 SERVER4 DB4 I use awk to grep only the server... (6 Replies)
Discussion started by: senthil3d
6 Replies

10. Shell Programming and Scripting

Concatenating column values with unique id into single row

Hi, I have a table in Db2 with data say id_1 phase1 id_1 phase2 id_1 phase3 id_2 phase1 id_2 phase2 I need to concatenate the values like id_1 phase1,phase2,phase3 id_2 phase1,phase2 I tried recursive query but in vain as the length of string to be concatenated in quite long. ... (17 Replies)
Discussion started by: jsaravana
17 Replies
Login or Register to Ask a Question