LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk help (https://www.linuxquestions.org/questions/linux-newbie-8/awk-help-4175436253/)

redhatuser1 11-08-2012 08:03 AM

awk help
 
Hi,

I am hoping someone can help - I don't know awk/sub so I'd like some help...with an explanation of how it works if possible..

I need to take the 8th column of a csv and replace any dots (".") with slashes ("/")....

So I know I can use awk to parse the csv file and print the necessary column:

Code:

awk -F "\"*,\"*" '{print $8}' thisfile.csv
How do I add the sub function to replace the print function??

This will be scripted as well...

I appreciate any and all help...

Edit sample string : this, this, this, this, this , this , this , 27.11.2011, this, this, this

I basically need the date in DD/MM/YYYY format

redhatuser1 11-08-2012 08:07 AM

so now I know the following is probably a fair bit easier:

Code:

awk -F "," '{print $8}' file.txt
I assume I need something like this (the single dot seems to cause problems)

Code:

awk -F "," '{gsub(".","/" $8; print}' file.txt >  outputfile.txt
This is replacing every character in the field with a /

Further edit - I am getting closer I think - this removes all the commas in the file:

Code:

awk -F "," '{gsub("[.]"."/" $8); print' file.txt

redhatuser1 11-08-2012 08:40 AM

Apologies I found the solution- it shows with enough googling you can find a solution:

Code:

awk -F "," '{$8==gsub("[.]","/"); print}' file.txt > output.txt


All times are GMT -5. The time now is 07:34 PM.