How to add number of fields throughout file together?
So, I have three problems that cover this subject.
First one asks me to find the number of fields in the file that contain the substring "he". I found the number of fields, but the problem I have is that they are displaying by each record. I want to add all of the records' fields together.
With this same text document:
"The quick brown fox jumped over the lazy dog's back.
The rain in Spain falls mainly on the plain.
The rain in Spain also falls on the mountains."
My code looks like this:
It is giving me this result:
"Number of fields in record containing 'he': 2
Number of fields in record containing 'he': 2
Number of fields in record containing 'he': 2"
What I want it to do is print
"Number of fields in file containing 'he': 6"
How would I accomplish that?
These are the two other problems, of a very similar type: I want to find the number of times the letter n appears in the text file, but I do not know how to add all the records' results together. My current code looks like this:
This gives me the result of:
"Number of 'n' in record: 1
Number of 'n' in record: 6
Number of 'n' in record: 6"
Instead, I need it to say
"Number of 'n' in file: 13"
The last problem is essentially the same, but instead of 'n', I need to look for the number of 'la' in the file.
I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want.
The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
I am looking for perl code to get following o/p. If a line has more than 7 fields then value in field 7 onwards is BHA_GRP1, BHA_GRP2, BHA_GRP3, BHA_GRP4 etc.
Here is example of what I am trying to achieve.
INPUT File:
VAH NIC_TYPE CONFIG SIZE_GB PILO KOM BHA_GRP1 BHA_GRP2 BHA_GRP3......
2... (1 Reply)
I'm facing a strange problem, please help me out.
Here we go.
I want to count number of fields in particular file.
filename and delimiter character will be passed through parameter.
On command prompt if i type following i get 27 as output (which is correct)
cat customer.dat | head -1 | awk... (12 Replies)
I have a file which is delimetered by ',' i need to filter out a file with respect to the number of fileds in each line.
a,s,d,f,g,h,j,k,l
1,2,3,3,4,5,6,7,6
a,2,3
4,5,6,7
in this
i neeed to filter out the lines with 8 column to another file and rest to another file.
so
... (3 Replies)
Hi,
I have a comma (,) delimited file, in which few fields are enclosed with in double quotes " ". I have to print the records in the file which donot have expected number of field with the line number.
File1
====
name,desgnation,doj,project #header#... (7 Replies)
Hi,
How to print the number of fields in each record with the line number?
Lets saw I have
3212|shipped|received|
3213|shipped|undelivered|
3214|shipped|received|delivered
I tried the code
awk -F '|' '{print NF}'
This gives me ouput as
3
3
4 (5 Replies)
Hi all, I have a tab separated file, and one of the fields is sub-delimited by colon. The problem is there can be zero to 4 colons within this field. When I try to change colons to tabs the result is a file with a differing number of fields.
I want to go from:
a:b:c:d:e
a:b:c
a:b:c:d:e
a... (4 Replies)
Hy!
I need to post-process some data files which have variable (and periodic) number of fields. For example, I need to square (data -> data*data) the folowing data file: -5.34281E-28 -3.69822E-29 8.19128E-29 9.55444E-29 8.16494E-29 6.23125E-29
4.42106E-29 2.94592E-29 1.84841E-29 ... (5 Replies)
hi,
would you help me?
i have file total.csv
"name","id","gender"
"a,"e23","f"
"b,"34d","g"
"c","45f","f"
"d","45s","f"
and file count.csv
3
i want to add file count to file total every row
name,id,gender,total_match
"a,"e23","f","3"
"b,"34d","g","3"
"c","45f","f","3"
... (4 Replies)
Hi,
Below are the sample files. x.txt is from an Excel file that is a list of users from Windows and y.txt is a list of database account.
$ head -500 x.txt y.txt
==> x.txt <==
TEST01 APP_USER_PROFILE
USER03 APP_USER_PROFILE
TEST02 APP_USER_EXP_PROFILE
TEST04 APP_USER_PROFILE
USER01 ... (3 Replies)