1
'awk 'BEGIN{FS=OFS=","}{print $2,$3,$5;}' <file>'

Using this command, is it possible to have it go through multiple files, ie file* at the end and if not how can i do this?

i have

file.01
file.02 
through file.20

All of the files can be replaced directly. An out file is not needed although i still need the split files to exist in their current chunks of 250mb

shellter
  • 36,525
  • 7
  • 83
  • 90
  • what OS (output of `uname -rvosi` please), and what version of awk, i.e.`awk --version`. Good luck. – shellter Nov 03 '15 at 22:49

1 Answers1

1

Yes - awk takes any number of files as arguments, and processes them in sequence. See man awk:

SYNOPSIS
       awk [ -F fs ] [ -v var=value ] [ 'prog' | -f progfile ] [ file ...  ]

and, in fact, you can access the name of the file current filename with the variable FILENAME.

You can do this with:

awk 'BEGIN{FS=OFS=","}{print $2,$3,$5;}' file*

for all files that start with the text file.

Brian
  • 2,172
  • 14
  • 24
  • I am new to using this command and scripting in general so how could i accomplish this? – Jonathon Vasile Nov 03 '15 at 21:17
  • @JonathonVasile `awk 'BEGIN{FS=OFS=","}{print $2,$3,$5;}' file.01 file.02` etc. or `cat file.* | awk 'BEGIN{FS=OFS=","}{print $2,$3,$5;}'` – jayant Nov 03 '15 at 21:22
  • @jayant when i run 'cat $(date +"%d-%m-%Y").WE.* | awk 'BEGIN{FS=OFS=","}{print $2,$3,$5;}' ' it will only scroll on screen and not overwrite the file – Jonathon Vasile Nov 03 '15 at 21:41
  • 1
    @JonathonVasile yes that's because awk doesn't modify the file. See http://stackoverflow.com/questions/16529716/awk-save-modifications-inplace – jayant Nov 03 '15 at 21:44