Thank you PHV. I guess I wasn't too far off. Am I correct in assuming that what this states is if x[1] is not empty then print all 6 fields "else" don't print anything. The "else" is basically implied?
Yes, I'm back with another challenge. Recently this script ran against an empty file (I just now became aware of this possibility) and it output the following:
,,,,,
Is there a way to make this script output an empty file if the file it is run against is empty of any data? Thank you for any...
I have a file that will have zero or more lines of data. What I need to do first is check the file to see if it has zero or 1 line of data. If it does I need to copy it to a specific directory as is, otherwise I need to run a function (which I already have) against it before sending it to the...
PHV, I found a slight problem on our end when I use your script:
BEGIN{FS=OFS=","}
function myprint(){
if(NR>1)print x[1],x[2],x[3],x[4],x[5],x[6]
split($0,x,",");b=$1
}
b!=$1{myprint();next}
{x[3]+=$3;x[5]+=$5}
END{myprint()}
Although created for mulitple lines of data we have the...
Thank you PHV this worked. However, I did not stop to consider the possibility that the input file may contain additional lines of information that are not related to each other but still aggregate the same:
0000229351,4,5.00,533017068270,31.96,UPAC
0000229351,4,3.00,533017068280,27.08,UPAC...
Thank you PHV. Sorry it took so long to respond. I forgot to mention I am using gawk in a windows command line environment and am receiving the following error:
C:\Windows\system32>awk -F, "NR==1{split($0,x,",")}NR>1{x[3]+=$3;x[5]+=$5}END{OF
S=",";print x[1],x[2],x[3],x[4],x[5],x[6]}"...
I am hoping someone can help me find a way to sum two columns but output the answer into a separate file using the first row of the original file as such:
0000229351,4,5.00,533017068270,31.96,UPAC
0000229351,4,3.00,533017068280,27.08,UPAC
0000229351,4,5.00,533017068291,31.96,UPAC...
Awesome! It looks like that was the problem. I originally put it in MS word and apparently the formatting threw it off. I did it in notepad and worked like a charm. Thank you very much!
Annihilannic thank you very much!
Tek-Tips rocks!
This is the contents of the file I created:
{
r[NR]=$0
if ($1!="") { ix=$1 }
}
$NF == "\"Y\"" { s[ix] }
END {
for (i=1;i<=NR;i++) {
split(r[i],a,",")
if (a[1]!="") { ix=a[1] }
if (!(ix in s)) { print r[i] }
}
}...
Feherke thank you for responding so quickly. I set it up as you stated but I received the following error:
gawk: -F
gawk: ^ invalid char ‘-‘ in expression
Also, does it matter what the extension is for the "separate" file (i.e., chino_10.awk)?
Thank you for responding Annihilannic. I attempted to make this work in a dos environment but continue to receive the following error: "The system cannot find the file specified". I am sure it's because I don't have the syntax correct yet but if, by chance, you have any additional tips I would...
I am completely new to shell scripting but have been assigned the task of creating several batch files to manipulate data in a windows environment. My final task requires me to find rows in a .csv document where the last column is “Y” then delete not only the duplicate(s) but the original as...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.