Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7905841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:39:34+00:00 2026-06-03T10:39:34+00:00

Okay so i am trying to write a simple awk to clear out some

  • 0

Okay so i am trying to write a simple awk to clear out some commas of some csv files i have.

Here is a few lines of sample data

  PRD,,,,PEWPRV100D,,,EWPRVU457D,,,,12/31/2011  10:09:14 PM,,,,,5,,,4,,
  PRD,,,,PEWPRV100D,,,EWPRVU250D,,,,12/31/2011  10:09:23 PM,,,,,67,,,69,,
  PRD,,,,PEWREF100D,,,EWREFU045D,,,,12/31/2011  10:09:40 PM,,,,,7,,,5,,
  PRD,,,,PEWPRV100D,,,EWPRVU191D,,,,12/31/2011  10:09:40 PM,,,,,6,,,5,,

As a simple first step, I want to perform this (what I ultimatly want to do is more complicated but this is the first thing I need to do and i cant even get this right 🙁 )

   PRD,PEWPRV100D,EWPRVU457D,12/31/2011  10:09:14 PM,5,4,
   PRD,PEWPRV100D,EWPRVU250D,12/31/2011  10:09:23 PM,67,69,
   PRD,PEWREF100D,EWREFU045D,12/31/2011  10:09:40 PM,7,5,
   PRD,PEWPRV100D,EWPRVU191D,12/31/2011  10:09:40 PM,6,5,

Here is my first attempt at an awk script

  #!/bin/awk 
  BEGIN{FS=",";} 
  {print $0,$4,$7,$11,$16,$19 }
  END{print "DONE"}

which produces

  PRD,,,,PEWPRV100D,,,EWPRVU457D,,,,12/31/2011  10:09:14 PM,,,,,5,,,4,,,,,,,
  PRD,,,,PEWPRV100D,,,EWPRVU250D,,,,12/31/2011  10:09:23 PM,,,,,67,,,69,,,,,,,
  PRD,,,,PEWREF100D,,,EWREFU045D,,,,12/31/2011  10:09:40 PM,,,,,7,,,5,,,,,,,
  PRD,,,,PEWPRV100D,,,EWPRVU191D,,,,12/31/2011  10:09:40 PM,,,,,6,,,5,,,,,,,

A more telling script I tried :

  #!/bin/awk 
  BEGIN{FS=",";} 
  {printf("$$%s$$", $0) }
  END{print "DONE"} 

which produces

 $$PRD,,,,PEWPRV100D,,,EWPRVU457D,,,,12/31/2011  10:09:14 PM,,,,,5,,,4,,$$
  $$PRD,,,,PEWPRV100D,,,EWPRVU250D,,,,12/31/2011  10:09:23 PM,,,,,67,,,69,,$$
  $$PRD,,,,PEWREF100D,,,EWREFU045D,,,,12/31/2011  10:09:40 PM,,,,,7,,,5,,$$
  $$PRD,,,,PEWPRV100D,,,EWPRVU191D,,,,12/31/2011  10:09:40 PM,,,,,6,,,5,,$$

showing (i think) that the FS=”,” is not setting the delimiter to a comma, since the whole line is seen as one column. I have also tried many different form of that line, none seem to make a difference. The man pages of the awk implementation say that FS is the var I should set. i have also tried hte -F flag, which did not help either.

Is there something obvious I am missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:39:35+00:00Added an answer on June 3, 2026 at 10:39 am

    In awk, $0 is not the first column — it’s the entire line. $1 is the first column, the second column is $2, and so forth. Thus, you presumably want to change this:

    {print $0,$4,$7,$11,$16,$19 }
    

    to this:

    {print $1,$5,$8,$12,$17,$20 }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay I been trying to work this out but unable too. I have a
Okay here is what I'm trying to do: I have a model object that
Okay, here is a very simple and fundamental question. If I have an application
Okay, so I'm trying to write a simple show/hide content button, but I want
Okay, here's what I'm trying to do. I have a drupal table (term_data) in
Okay, guys i have been trying to define a Stack , each node also
Okay, I'm trying to write a ruby simulation of my grandmother. I can't quite
I am trying to write a simple Bash script to monitor MySQL replication status.
Okay, I am trying to write a LINQ query with a Join in it,
I'm trying to write a simple program to alert me when ram is getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.