cool! that works on line 2.
Further question. What if I want to apply the same formula on all lines?
That's not what you showed, though. Your example data only showed line 2 being changed.
And changing all lines might do something to your header line, which would be bad, unless you don't actually have a header line.
To modify absolutely all lines, remove the 'NR==2', which means, 'only run this code block when NR (line number) is 2'.
-F, and -v OFS=, set the input and output separators, so you don't accidentally change your commas into spaces.
I've highlighted the part which changes the column and made the code a little more obvious. ++ is an operator borrowed from the C language, which means 'add 1 to this variable', that's the longhand equivalent.
$ doesn't mean variable in awk, though. Any unquoted string of letters is a variable. $ means "use this variable or expression as a column" -- so when N=4, $N gives you column 4. And $N=5 sets column 4 to the value of 5. Etc.
So, for every line, this loops over all columns, and adds 1 to any which are purely numbers(i.e. match the regex /^[0-9]+$/ ).
The 1 at the end of the line makes it print every single line.
If I understood the problem correctly, I think this might be closer to what was wanted:
This increments the second field by 1 and the 3rd field by 5 as long as both fields are non-null (after removing spaces). Change the values shown in red if you want to use different increments.
If the file raw contains:
the output will be:
This User Gave Thanks to Don Cragun For This Post:
Here is my select that I have to identify the child records that are Open (e.c7 < 6000) when the parent (t2068) c.c7 > 3
t2068 c INNER JOIN t1533 e ON e.c1000000829 = c.c301572100
c.c7 > 3... (2 Replies)
I want to check the value of all MySQL columns.(column name is "status") via bash script.
If value is "0" at I want to make only single column value to "1"
I have many "0" values on mysql database(on "status" column)
"0" means it is a draft post. I want to publish a post. I... (2 Replies)
I am using INFORMIX 8 and trying to update column value by apending '09' to existing record .
update sample_data_table set Name = Name||22 where id = 90 and state = NY
This worked fine in oracle Database,But throwing error in informix .
I need output as Ravi22 for Ravi record in... (0 Replies)
I Have a file a.txt in the below format
1 23 50
1 25 6666666666666
1 23 34
If the third column value is greater than two digit then make it 0
New Data File
1 23 50
1 25 0
1 23 34
Need your help regarding this (5 Replies)
I have to update my file from server file.
Server file A on location
KJL0405... (3 Replies)
I need to update a text file within a loop so that the value is added creating a new column at the end. I cannot use paste because I dont know the number of files. If I use >> the value is added after the last row. Please help.
Column 1 Column2
- ... (2 Replies)
I was wondering if anyone knew a good/safe way to update a single column in a table that could contain upto 8 million rows...
simple command like:
UPDATE set blah=foo where bar=XXX;
I will be running this on tables being written to and tables that have already been created.
... (3 Replies)
I am new to scripting and i have an application from which i will export into a csv file as follows
Column1, Column2, Column3
Sno1, Folder\Test.txt, Fail
Sno2, Folder\Test1.txt, Pass
Sno3, Folder\Test2.txt, Fail
Now i need to change the column2 in all the rows from "Folder\"
... (1 Reply)
I need to write a shell script in UNIX that should accept booking number as an argument and update it with value "NULL" if the transaction date is greater than 2 years. Booking number and transaction_date are the two columns of the table table_booking.
Something like this, through... (3 Replies)
I have two files:
If col1=col1,col2=col2 and col3=3 of fileA to fileB, then take value in 4th col of fileB and replace... (5 Replies)