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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:51:40+00:00 2026-05-19T23:51:40+00:00

I am trying to manipulate a text file. I’ve got most of it figured

  • 0

I am trying to manipulate a text file. I’ve got most of it figured out myself, but I’m stumped with why sed seems to go into infinite loop mode. The text file can be downloaded from census.gov.

At the moment, I just want a list of states that I can throw into a for loop to do some state-specific processing. So far, I’ve got this. (I’m not a bash expert, suggestions are welcome.

sed 1d tables/ansi.csv | awk -F "," '{print $1}' | uniq | tr \n : | sed s/:/" "/g

I want to put this into $() to use the output in a for loop, but for some reason, sed is hanging up and not exiting. I actually need to add a couple of things to the final sed command, to properly format things, but I want to get this running correctly before I go any further.

In the end – I want something that looks like (just showing the first few):

"AL" "AK" "AZ" "AR" "CA" "CO" ....

Right now, sed returns more of less what I expect and returns (just showing the last few)

...."MP" "PR" "UM" "VI" "

But, rather than exiting, sed hangs and I have to Ctrl-C out of the script. If I remove the final sed statement, the little script runs as I would expect, without hanging.

So, why on earth is this hanging?

  • 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-19T23:51:41+00:00Added an answer on May 19, 2026 at 11:51 pm

    I would suggest putting the sed script inside quotes:

    sed 1d tables/ansi.csv | awk -F "," '{print $1}' | uniq | tr '\n' : | sed 's/:/" "/g'
    

    The reason that sed seems to “hang” may be that tr has removed the final newline which sed requires. By the way, the newline argument to tr needs to be quoted.

    However, the whole thing can be done in AWK:

    awk -F, 'NR > 1 {a[$1]=$1} END { delim=":"; num=asort(a); for (i=1;i<=num;i++) printf "\"%s\" ",a[i]; printf "\n"}' tables/ansi.csv
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to manipulate a .csv file to remove text at the beginning of
I am trying to use Python in order to manipulate a text file from
I am trying to manipulate a conditional string outputted from SAS into the right
I'm looking for a good python library to manipulate subversion repositories. I'm trying out
New to VB.net, just trying to figure out how to properly manipulate the asp:Label
I'm trying to manipulate a xml file from sharepoint document library with powershell. Unfortunately
I'm trying to manipulate the HTML through getElementsByClass() but for some reason it doesn't
I'm trying to make a little script to manipulate a txt file with a
I'm trying to read character by character from a text file until EOF, put
I am trying to parse a text file the contains numeric data. I have

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.