Split one file into multiple files based on delimiter

A one liner, no programming. (except the regexp etc.) csplit –digits=2 –quiet –prefix=outfile infile “/-|/+1” “{*}” tested on: csplit (GNU coreutils) 8.30 Notes about usage on Apple Mac “For OS X users, note that the version of csplit that comes with the OS doesn’t work. You’ll want the version in coreutils (installable via Homebrew), which … Read more

Tab separated values in awk

You need to set the OFS variable (output field separator) to be a tab: echo “$line” | awk -v var=”$mycol_new” -F’\t’ ‘BEGIN {OFS = FS} {$3 = var; print}’ (make sure you quote the $line variable in the echo statement)

Show filename and line number in grep output

I think -l is too restrictive as it suppresses the output of -n. I would suggest -H (–with-filename): Print the filename for each match. grep -Hn “search” * If that gives too much output, try -o to only print the part that matches. grep -nHo “search” *

How to use awk sort by column 3

How about just sort. sort -t, -nk3 user.csv where -t, – defines your delimiter as ,. -n – gives you numerical sort. Added since you added it in your attempt. If your user field is text only then you dont need it. -k3 – defines the field (key). user is the third field.

What are NR and FNR and what does “NR==FNR” imply?

In awk, FNR refers to the record number (typically the line number) in the current file, NR refers to the total record number. The operator == is a comparison operator, which returns true when the two surrounding operands are equal. This means that the condition NR==FNR is only true for the first file, as FNR … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)