I am using the below code to check the number of columns in a delimited file are same as expected. Code is give below
Here the challenge is that , delimiter is different for each file, it can be pipe, comma, or semi colon.I want to pass the delimiter value into the above awk command using external parameter.Currently I am passing the number of fields as external parameter.
Here is an example for this you could set it as follows.
Similarly you could set it for any file as per your need. As you haven't shown us complete requirement so one could take it as a starting point, let me know if this helps.
Actually my requirement is to find out where the number of columns present in the file is same a predefined.
I have two files A & B
A is suppose to have three columns and is a pipe delimited file
I want to write a awk command to find the records where number of columns are not equal to three.So if run my awk command to the file A, I should get out put as
B is suppose to have two columns and is a comma delimiter file
I want to write a awk command to find the records where number of columns are not equal to two.So if run my awk command to the file B, I should get out put as
What I need is a command command where I will be able to pass the number of columns and delimiter as external parameter while running the script.If you see my below script I am passing number of columns as a parameter
In addition to that I need to pass the delimiter also as a parameter. I tried like below, but not working
Actually my requirement is to find out where the number of columns present in the file is same a predefined.
I have two files A & B
A is suppose to have three columns and is a pipe delimited file
I want to write a awk command to find the records where number of columns are not equal to three.So if run my awk command to the file A, I should get out put as
B is suppose to have two columns and is a comma delimiter file
I want to write a awk command to find the records where number of columns are not equal to two.So if run my awk command to the file B, I should get out put as
What I need is a command command where I will be able to pass the number of columns and delimiter as external parameter while running the script.If you see my below script I am passing number of columns as a parameter
In addition to that I need to pass the delimiter also as a parameter. I tried like below, but not working
If you invoke your script with two parameters where the 1st parameter is the field separator and the 2nd parameter is the expected number of fields, just using:
will give you output where each line is the line number of a line with the wrong number of fields, the number of fields found on that line, and the text from that line. Another way to write that awk script and get identical results would be:
These 2 Users Gave Thanks to Don Cragun For This Post:
I have two files, file1 and file2 who have identical number of rows and columns. However, the script is supposed to be used for for different files and I cannot know the format in advance. Also, the number of columns changes within the file, some rows have more and some less columns (they are... (13 Replies)
Hello All,
I have a requirement in which i will be given a sql query as input in a file with dynamic number of columns. For example some times i will get 5 columns, some times 8 columns etc up to 20 columns.
So my requirement is to generate a output query which will have 20 columns all the... (7 Replies)
hi,
i have a file with many records and each record may or may not have 6 columns.
for example
file1 :
first second third fourth fifth sixth
first second third fourth fifth
first second third fourth fifth sixth
first second third fourth fifth sixth seventh eigth
if i cat the file and... (21 Replies)
How to find the number of columns in xml file.
i tried following command.
#!bin/ksh
cat $1 | grep -c "</mdm:attribute>"
exit 0
but i am not getting accurate result which is not matching with the manual count.
data format :
<mdm:attribute> value </mdm:attribute> (6 Replies)
Hello Guys
I have a flat file with few thousands of rows.
Now each rows have different number of columns
I want to delete the rows which has not equal to 749 columns
Can you guys please let me know how to do the same
Your help is much appreciated. (2 Replies)
Hi,
I want to subtract a number from all columns except the first column. I have a number of files each having different columns around 60/70. How to do that in awk or any other command?
Thanks
Input
Col 1 Col 2 Col3 - - - - Col55
1 .0123 .098 - - - 0.6728
2 - -... (3 Replies)
i have a file which may have 'n' number of columns
1 222 fafda 32 afdaf 4343 4343
234 43fdaf 4343 fdd fdfd fdfd fdd fdfd fdfd
fdfd fdfd fdfd fdd fdfd fdfd
need to concatenate the columns with... (3 Replies)
Hi all,
may seem a very stupid question.but me stuck up in it for long....
How to find the number of columns in a ASCII file.
EX:-Demo.lst
songs 1 34 45 67
Number of columns should be 5.
Regards,
Anindya
;) (13 Replies)
I get the point of number subtraction in one column
awk 'NR==1 {n=$1; next}; {n-=$1} END {print n}' inputfile
but I cannot figure it out how to do this to multiple
columns.
awkward. (6 Replies)
I am given a file with a list of names for the first 20 characters. The 20 characters after is a list of names that somebody is supposed to team up with.
Now i'm trying to write a simple script that will read a name somebody inputs and then looks only in the first 20 characters.
For example.... (2 Replies)