LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-08-2012, 09:03 AM   #1
redhatuser1
Member
 
Registered: Sep 2009
Posts: 55

Rep: Reputation: 0
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

Last edited by redhatuser1; 11-08-2012 at 09:04 AM.
 
Old 11-08-2012, 09:07 AM   #2
redhatuser1
Member
 
Registered: Sep 2009
Posts: 55

Original Poster
Rep: Reputation: 0
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

Last edited by redhatuser1; 11-08-2012 at 09:34 AM.
 
Old 11-08-2012, 09:40 AM   #3
redhatuser1
Member
 
Registered: Sep 2009
Posts: 55

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
running series of awk commands from an awk file oreka18 Programming 3 05-16-2012 02:13 AM
awk error awk: line 2: missing } near end of file boscop Linux - Networking 2 04-08-2012 11:49 AM
[SOLVED] call awk from bash script behaves differently to awk from CLI = missing newlines titanium_geek Programming 4 05-26-2011 10:06 PM
[SOLVED] awk: how can I assign value to a shell variable inside awk? quanba Programming 6 03-23-2010 03:18 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 05:11 PM


All times are GMT -5. The time now is 10:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration