smoothjabz
smoothjabz

Reputation: 15

Loop over csv files, output tail -n to new csv for each

I am writing a bash script that loops over x number of logfiles and sends the most recent 10 entries for each logfile into a separate csv. So if I have 25 logfiles, after running the script I will expect to have 25 new csv files, each containing the 10 most recent lines.

Here is something along the lines of what I am trying to make:

#!/bin/bash
for file in /path/to/logs/*.log; 
    do tail -n 10 > "$file".csv
done

I can't seem to get it to loop over all the files - instead, it hangs on one. How do I get this small snippet to loop over each file?

Upvotes: 0

Views: 543

Answers (1)

Matias
Matias

Reputation: 567

I think you are missing the $file parameter in tail command. Could you try adding "$file" at the end of it?

#!/bin/bash
for file in /path/to/logs/*.log; 
    do tail -n 10 "$file" > "$file".csv
done

Upvotes: 1

Related Questions