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

  • Home
  • SEARCH
  • 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 7746645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:19:52+00:00 2026-06-01T10:19:52+00:00

I am converting a CSV file into a table format, and I wrote an

  • 0

I am converting a CSV file into a table format, and I wrote an AWK script and saved it as my.awk. Here is the my script:

#AWK for test
awk -F , '
    BEGIN {
        aa = 0;
    }
    {
        hdng = "fname,lname,salary,city";
        l1 = length($1);
        l13 = length($13);
        if ((l1 > 2) &&  (l13 == 0)) {
            fname = substr($1, 2, 1);
            l1 = length($3) - 4;
            lname = substr($3, l1, 4);
            processor = substr($1, 2);
            #printf("%s,%s,%s,%s\n", fname, lname, salary, $0);
        }

        if ($0 ~ ",,,,")
            aa++
        else if ($0 ~ ",fname")
            printf("%s\n", hdng);
        else if ((l1 > 2) && (l13 == 0)) {
            a++;
        }
        else {
            perf = $11;
            if (perf ~/^[0-9\.\" ]+$/)
                type = "num"
            else
                type = "char";
            if (type == "num")
                printf("Mr%s,%s,%s,%s,,N,N,,\n", $0,fname,lname, city);
        }
    }
    END {
    } ' < life.csv > life_out.csv*

How can I run this script on a Unix server? I tried to run this my.awk file by using this command:

awk -f my.awk life.csv
  • 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-01T10:19:54+00:00Added an answer on June 1, 2026 at 10:19 am

    The file you give is a shell script, not an awk program. So, try sh my.awk.

    If you want to use awk -f my.awk life.csv > life_out.cs, then remove awk -F , ' and the last line from the file and add FS="," in BEGIN.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I imported a table from a CSV file into MySQL using this query: LOAD
I'm writing application for downloading CSV file from web and inserting data into table
Is this possible to take delimeter other than comma for converting into CSV file....because
I'm reading in a csv file from a datatable and something is happening. Here's
Im trying to load a csv file into a datatable using oledb. This is
My Code is reading in a CSV file and converting the time stamp column
I'm adding data from a csv file into a database. If I open the
I'm converting a csv file to xml using the following function: I want to
I am importing data from a CSV file. One of the fields has an
I have a function that converts a .csv file to a datatable. One of

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.