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 726949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:30:39+00:00 2026-05-14T06:30:39+00:00

Operating System: OSX Method: From the command line, so using sed, cut, gawk, although

  • 0

Operating System: OSX
Method: From the command line, so using sed, cut, gawk, although preferably no installing modules.

Essentially I am trying to take the first column of a csv file and parse it to a new file.

Example input file

EXAMPLEfoo,60,6
EXAMPLEbar,30,6
EXAMPLE1,60,3
EXAMPLE2,120,6
EXAMPLE3,60,6
EXAMPLE4,30,6

Desire output

EXAMPLEfoo 
EXAMPLEbar
EXAMPLE1
EXAMPLE2
EXAMPLE3
EXAMPLE4

So I want the first column.

Here is what I have tried so far:

awk -F"," '{print $1}' in.csv > out.txt

awk -F"," '{for (i=2;i<=NF;i++)}' in.csv > out.txt

awk -F"," 'BEGIN { OFS="," }' '{print $1}' in.csv > out.txt

cat in.csv | cut -d \, -f 1 > out.txt

None seem to work, either they just print the first line or nothing at all, so I would assume it’s failing to read line by line.

  • 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-05-14T06:30:39+00:00Added an answer on May 14, 2026 at 6:30 am

    Your last option works perfectly for me:

    $ cat > in.csv  # Then pasted the example input followed by Ctrl+D:
    EXAMPLEfoo,60,6
    EXAMPLEbar,30,6
    EXAMPLE1,60,3
    EXAMPLE2,120,6
    EXAMPLE3,60,6
    EXAMPLE4,30,6
    [Ctrl+D]
    $ cat in.csv | cut -d, -f1
    EXAMPLEfoo
    EXAMPLEbar
    EXAMPLE1
    EXAMPLE2
    EXAMPLE3
    EXAMPLE4
    

    Maybe line endings are biting you here? If the file has DOS-style or even old-Mac-style line endings, this might cause strange behaviour. Try running file in.csv and see what it comes up with.

    $ file in.unix.csv
    in.unix.csv: ASCII text
    $ file in.dos.csv
    in.dos.csv: ASCII text, with CRLF line terminators
    

    If the latter is your situation, use the dos2unix tool to convert the file.

    Edit: On OS X, it seems flip is what you want.

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

Sidebar

Related Questions

Does any operating system provide a mechanism (system call — not command line program)
Does anyone know how to get the operating system information from a microsoft sql
I'm trying the following Java code to shut down Windows operating system. I'm using
I'm having trouble installing RubyGems on my Mac OS X Lion operating system. I
What operating system and UI toolkit is this? It's not some fake Hollywood user
I just upgraded my operating system to Windows 7. Visual Studio 2008 also seems
In windows operating system, the stack memory is a thread-specific storage, and the call
What's the best operating system to study in order to write your own x86
Is there any Operating System that do not support threading? I read somewhere CLI
I have a 64 bit windows operating system and I use VS2008 to write

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.