I am using the awk command to replace ',' by '\t' (tabs) in a csv file. I would like to apply this to all .csv files in a directory and create .txt files with the tabs.
How would I do this in a script?
I have the following script called "csvtabs":
awk 'BEGIN {
FS = ","
OFS = "\t"
}
{
$1 = $1
for (i = 1; i <= NF; i++) {
if ($i == "") {
$i = "null"
}
}
print $0
}' test.csv > test.txt
which makes test.txt with tabs. However, this only works for one file (test.csv) which I have to change each time to the file I want to convert. Since I have many files I want to make the process faster.
Alternatively, if the solution is too difficult, how can I alter the script to take in files at the command line. In other words run:
Looking at column 2 or 3 (maybe specified at command line) I want to find the two maximums and write to file (in case of column 2 it would be 4 and 6). Since this is somewhat complicated I first was trying to find just the maximum from one of the columns. Therefore, I tried to add this to the awk command:
As you can probably tell, I have a c background. Anyways, this isn't giving me the maximum number. Is this even the right approach for what I ultimately want?
awk does not run inside your shell, hence cannot set shell variables. If you want to get a value out of awk, you have to print it somehow. Since you're already using stdout for data, maybe stderr?