Can you please help me in knowing what is the problem in the code what I have written?
Hi rahulsk,
In case it isn't obvious from what others have already said, your code didn't work because your awk script produces output (when there are one or more empty fields in the inpu) that your second read statement interprets to be part of a field separator instead of an empty field.
Furthermore, your use of echo (with an unquoted variable expansion) would convert any sequence of one or more <space> and <tab> characters to a single <space> character. (This doesn't matter with the supplied sample data, but if your input was something like:
it could make a huge difference. And, with input like the above, the echo and awk pipeline converting <comma>s to <space>s would further exacerbate the problem changing <space> and <tab> characters in your input data into field separators and may add lots of words to the contents of the last data field.)
Using a single read statement with a <comma> as the field separator instead of a read statement, an echo statement, an awk command, and another read statement gets rid of two unnecessary writes of your data, gets rid of two unnecessary reads of your data, gets rid of the invocation of two unneeded shell built-in utilities, and gets rid of one unneeded external utility invocation as well as getting rid of several places in the pipeline where data can be corrupted.
I have the following a.txt file
A|1|2|3|4|5|
A||2|3|0||
A|1|6||8|10|
A|9|2|3|4|1|
A|0|9|3|4|5|
A||2|3|4|5|
A|0|av|.9|4|9|
I use the following command to count null values for 2nd field
awk -F"|" '!$2 { N++; next } END {print N}' a.txt
It should give the result 2, but it is giving... (2 Replies)
Using awk I am trying to replace all blank or null values with a . in the tad delimited input. I hope the awk is close. Thank you :).
input
name test
sam 1
liz 2
al
1
awk
awk 'BEGIN{FS=OFS="\t"}{for(i=1;++i<NF;)$i=$i?$i:"."}1'input
awk 'BEGIN { FS =... (6 Replies)
Hi All
I had requirement where I need to re-order columns in a file by using a control file.
here is the ctrl file
c1
c2
c3
source file
c3 | c1 | c2
a | b| c
I should create output file based on the ctrl file columns
o/p should look like this
c1 | c2 | c3
b| c|a
I wrote some... (9 Replies)
I need to develop a script where I will take two date arguments as parameter date1 and date2 which will in format YYYYMM.
Below is the input file say sample.txt.
sample.txt will have certain blocks starting with P1.
Each block will have a value 118,1:TIMESTAMP.
I need to compare the... (7 Replies)
hello all,
in the following code a -> next should print zero, but it is giving the output as 0xbf940000
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Node
{
public:
int data;
Node *next;
Node(int n=1)
{
data=10;
next=0;
}
};
void main()... (3 Replies)
I am using below code to validate the source file,code working fine but if any column contains null value then below code throwing error actually it should not.how to customize the below code to handle null null values also.
When I run the script with below source data getting “date error”, as... (2 Replies)
I'm filling in a table of values for grades. I decided to go with reading into a hash from the files but I'm coming up with an error when printing a value that does not exist. I need to know if I can on-the-fly print a space (" ") or blank in place of the grade.
Here's what the output should... (2 Replies)
Hello everyone
I am doing a join command. Obviously, before I need two files sorted first. ( Both files have headers and have about 2 million lines each one )
The problem is, one of the files has null values in the key to sort (which is the first filed ). For example I have the original... (4 Replies)
Hi
I have a file with the values
abc
res
set
kls
lmn
ops
i want to sort this file with the null values at the bottom of the file
OUTPUT should look like this
abc
kls
lmn
ops (6 Replies)
Hi,
Can someone help me comparing Null values.
Scenario is as follows:
I have a variable which "cache_prd" which can have either some integer or nothing(Null)
if it is integer I have to again do some comparision but these comparisons give me this error:( "line 32: [: 95: unary operator... (3 Replies)