uco
asked on
printing values from file
Hi
I have these 8 columns in file attacehd
separated by pipe to be emailed as report.Each column in
the file separated has to be given a name and printed to file email_file.txt and emailed
as shown
field name values
----------- -------
Field1 I,MM,O,P,V
Field2 00,10,17 ,etc
Field3
---
Field8 F, P
mailx -s "subjcet" -c $tempMail < email_file.txt
I have these 8 columns in file attacehd
separated by pipe to be emailed as report.Each column in
the file separated has to be given a name and printed to file email_file.txt and emailed
as shown
field name values
----------- -------
Field1 I,MM,O,P,V
Field2 00,10,17 ,etc
Field3
---
Field8 F, P
mailx -s "subjcet" -c $tempMail < email_file.txt
Is it possible to show how the files look like. Change the values for security.
Here is a script to do it
Try this first. If it works, email with the command you mentioned.
#!/bin/bash #Or use ksh
file=$(<FILENAME)
for ((i=1;i<=8;i++))
do
printf "Field $i: "
echo $file | cut -d'|' -f1
file=$(echo $file | cut -d'|' -f2-)
done > email_file.txt
Try this first. If it works, email with the command you mentioned.
Or awk:
awk '{split($0,A,"|"); for(i=1;i<=8;i++) B[i]=B[i] A[i] ","} END {for(j=1;j<i;j++) print "Column#" j, B[j]}' inputfile | sed 's/,$//' | tee email_file.txt | mailx -s "Values" uco@domain.tld
ASKER
Hi
It is close but
Two changes needed
I dont want commas if there are no more values in a column
Column names are not seqeuntial, they are different
Place
City
Modifier
Code
Type
Risk
Eval
Hype
thanks
It is close but
Two changes needed
I dont want commas if there are no more values in a column
Column names are not seqeuntial, they are different
Place
City
Modifier
Code
Type
Risk
Eval
Hype
thanks
Which one do you want to use? The first one or awk?
ASKER
sorry! The first one is not working, I am using the awk one
OK:
awk 'BEGIN {NAMES="Place City Modifier Code Type Risk Eval Hype"; F=split(NAMES,N," ")}
{split($0,A,"|"); for(i=1;i<=F;i++) B[i]=B[i] A[i] ","}
END {for(j=1;j<i;j++) printf "%-10s%s\n", N[j], B[j]}' inputfile | sed 's/,*$//' \
| tee email_file.txt | mailx -s "Values" uco@domain.tld
ASKER
Hi
Works great
Appreciate if you could get them in this style with header Field Name and Values.
If a column has more than 30 values it goes to next line as shown below. Each line dont have more than 30 values
field name values
----------- -------
Field1 I,MM,O,P,V,-----30
31,32,33 -------60
Field2 00,10,17 ,etc
Field3
---
Field8 F, P
Works great
Appreciate if you could get them in this style with header Field Name and Values.
If a column has more than 30 values it goes to next line as shown below. Each line dont have more than 30 values
field name values
----------- -------
Field1 I,MM,O,P,V,-----30
31,32,33 -------60
Field2 00,10,17 ,etc
Field3
---
Field8 F, P
A word and a blow.
awk 'BEGIN {NAMES="Place City Modifier Code Type Risk Eval Hype"; F=split(NAMES,N," ")}
{split($0,A,"|"); for(i=1;i<=F;i++) {if(NR%30==0) A[i]=A[i] ",\n ";
else A[i]=A[i] ","; B[i]=B[i] A[i]}}
END { {printf "%-14s%s\n%-14s%s\n", "Field Name", "Values", "----------", "------"}
{for(j=1;j<=F;j++) printf "%-14s%s\n\n", N[j], B[j]}}' inputfile \
| sed 's/,*$//' | egrep -v "^[ ]*$" \
| tee email_file.txt | mailx -s "Values" uco@domain.tld
wmp
ASKER
Great ! what could I Say, Simply Suerb, Is there way in expert exchange I can directly assign quetion to you?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great Work, to the point, Simply Superb