Solaris - Filter columns in text file and adding new column
Hello,
I am very now to this, hope you can help,
I am looking into editing a file in Solaris, with dinamic collums (lenght varies) and I need 2 things to be made, the fist is to filter the first column and third column from the file bellow file.txt, and create a new file with the 2 filtered collums, plus a third column with a value (0, 1 or 2) depending on the values of the second collum (0 for values 0-10, 1 for values 11-100, and 2 for values above 100)
EXAMPLE:
ORIGINAL FILE:
RESULT FILE:
NOTE: Collumns are alligned in original file, here in fórum they got out of place
---------- Post updated at 12:02 PM ---------- Previous update was at 11:59 AM ----------
As preiously stated, in original file collumns are alligned. In bold the values to filter: EH.ERROR.ADB_INSERT --------- 5* 0 11 0.0 Kb
Thank you very much for the reply, it has helped me a lot!!!
However I need an extra upgrade I guess shouldn´t be too complicated to implement:
The awk command gave me the result I needed, however I will need to change thresholds depending on the domain (eg: EH, ERP, etc), and above that add 2 extra columns with the min and max thresholds that are set for that row.
NOW:
Any help is very much appreciatted!! Thank you in advance for your time!
Being given requirements little bits at a time, instead of giving us all of the requirements up front wastes our time and is likely to introduce significant delays in getting the results you want...
You explicitly state that the lower bound for range 1 is 0 and in2nix4life's script assumes that $5 will never contain a negative number. (If a negative number is given, in2nix4life's script will print the range value for the previous input line.)
You said that field widths will vary but in2nix4life's script assumed upper bounds of 40 characters for column 1 and 10 characters for column 5.
The following script seems to meet your updated requirements (and it should be clear how to add additional domains with different sets of ranges). This script reads the file twice; the 1st pass gets the maximum field widths present in your input, and the 2nd pass prints the results. If column 5's value is less than zero, this script will print -1 for the range code. You can ignore that test if you know no input will ever have a negative value, or you can do something else where that test occurs if you want to print an error message, just remove that line's data from the output, or take some other action.
Since you said you're doing this on a Solaris system, I specified /usr/xpg4/bin/awk (instead of the default /bin/awk or /usr/bin/awk) as the utility to use to run this awk script. If you want to run it on another system, change the first line of the script from:
to just:
This User Gave Thanks to Don Cragun For This Post:
Hello,
Can someone please help in below requirement.
My requirement is to add date before to first column,some text before 1st,2nd coulmns and insert a new column in between 2 and 3 columns.
input file.
aa 123 dddd
aa 667 kdkdk
ddj 738 kkkk
aa 123 dddd
aa 667 ... (5 Replies)
Hi Folks,
I have a text file with lots of rows with duplicates in the first column, i want to filter out records based on filter columns in a different filter text file.
bash scripting is what i need.
Data.txt
Name OrderID Quantity
Sam 123 300
Jay 342 498
Kev 78 2500
Sam 420 50
Vic 10... (3 Replies)
Hi,
I am not so familiar with bash scripting and would appreciate your help here.
I have a text file 'input.txt' like this:
2 3 4
5 6 7
8 9 10
I want to store each column in an array like this
a ={2 5 8}, b={3 6 9}, c={4 7 10}
so that i can access any element, e.g b=6 for the later use. (1 Reply)
Hi,
I would like to add a new column containing the row numbers to a text file. How do I go about doing that? Thanks!
Example input:
A X
B Y
C D
Output:
A X 1
B Y 2
C D 3 (5 Replies)
Hi,
I have a tab delimited text file with three different columns. I want to add an extra column to the text file. The extra column will be the second column and it will equal third column - 1. How do I go about doing that? Thanks!
Input:
chr1 788822 rs11240777
chr1 1008567 rs9442372... (2 Replies)
I have a space delimited text file with two columns. I would like to add NA to the first column of the text file.
Input:
19625 10.4791768259
19700 10.8146489183
19701 10.9084026759
19702 10.9861346978
19703 10.9304364984
Output:
NA19625 10.4791768259
NA19700 10.8146489183... (1 Reply)
Hi All ,
Kindly help me with this soln
awk '{printf "%s %7s \n", $1,$c}' infile
where
value of variable c I am externally giving input
But executing the above command shows all the columns of infile where as I want only 1st column of infile and 2nd column should print value c (8 Replies)
Good afternoon to everyone,
I have some input and output from various widgets that I am trying to get to play nicely together. Basically I would like to stay out of excel and be able to automate the entire process. I have read some posts here about how to use awk, nawk, etc, to do similar... (9 Replies)
Dear all,
Does anyone know how I could to add a column of numbers (1s, or 2s, or..., or 6s) to two-column text files (tab-delimited), where the specific number to be added varies as a function of the file naming?
Currently, each of my text files has two columns, so the column with the... (12 Replies)
Hi,
I want to write a shell script which increments a particular column in a row from a text file and then adds another row below the current row with the incremented value .
For Eg .
if the input file has a row :
abc xyz lmn 89 lm nk o p
I would like the script to create something like... (9 Replies)