CLAWRIM Wiki

Computing Lab for Advanced Water Resources Informatics and Modeling

User Tools

Site Tools


shell_scripting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
shell_scripting [2023-09-21 04:45 pm] – [Merging CSV files in the current directory] hchoshell_scripting [2023-09-21 05:15 pm] (current) hcho
Line 15: Line 15:
 # because we don't want to skip the head line from the first file # because we don't want to skip the head line from the first file
 first=1 first=1
 +# for each of *.csv file names, assign it to i
 for i in *.csv; do for i in *.csv; do
   # if you repeat this script, we don't want to merge   # if you repeat this script, we don't want to merge
Line 34: Line 35:
 done > merged.csv # forward any outputs from the above for loop done > merged.csv # forward any outputs from the above for loop
                   # to merged.csv                   # to merged.csv
 +</code>
 +
 +===== Finding the order of a column in a CSV file =====
 +
 +<code bash>
 +head -1 merged.csv |
 +sed 's/"//g; s/,/ /g' |
 +awk '{
 +  for(i=1; i<=NF; i++)
 +    if($i == "TOBS")
 +      print i
 +}'
 +</code>
 +
 +===== Counting non-null records in a column in a CSV file =====
 +
 +<code bash>
 +tail -n +2 merged.csv |
 +sed 's/"//g; s/,/ /g' |
 +awk '{
 +  if($57 != "")
 +    count++
 +}
 +END{
 +  print count
 +}'
 </code> </code>
shell_scripting.1695336339.txt.gz · Last modified: 2023-09-21 04:45 pm by hcho

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki