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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:03:56+00:00 2026-05-28T08:03:56+00:00

I am using Fedora, and bash to do some text manipulation with the files

  • 0

I am using Fedora, and bash to do some text manipulation with the files I have. I am trying to combine a large number of files, each one with two columns of data. From these files, I want to extract the data on the 2nd column of the files, and put it in a single file. Previously, I used the following script:

paste 0_0.dat 0_6.dat 0_12.dat | awk '{print $1, $2, $4}' >0.dat

But this is painfully hard as the number of files gets larger — trying to do with 100 files. So I looked through the web to see if there’s a way to achieve this in a simple way, but come up empty-handed.

I’d like to invoke a ‘for’ loop, if possible — for example,

for i in $(seq 0 6 600)
do
  paste 0_0.dat | awk '{print $2}'>>0.dat
done

but this does not work, of course, with paste command.

Please let me know if you have any recommendations on how to do what I’m trying to do …

DATA FILE #1 looks like below (deliminated by a space)

-180 0.00025432
-179 0.000309643
-178 0.000189226
.
.
.
-1 2E-5
0 1.4E-6
1 0.00000
.
.
.
178 0.0023454268
179 0.002352534
180 0.001504992

DATA FILE #2

-180 0.0002352
-179 0.000423452
-178 0.00019304
.
.
.
-1 2E-5
0 1.4E-6
1 0.00000
.
.
.
178 0.0023454268
179 0.002352534
180 0.001504992

First column goes from -180 to 180, with increment of 1.

DESIRED
(n is the # of columns; and # of files)

-180 0.00025432 0.00025123 0.000235123 0.00023452 0.00023415 ... n
-179 0.000223432 0.0420504 0.2143450 0.002345123 0.00125235 ... n
.
.
.
-1 2E-5
0 1.4E-6
1 0.00000    
.
.
.
179 0.002352534 ... n
180 0.001504992 ... n

Thanks,

  • 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-28T08:03:56+00:00Added an answer on May 28, 2026 at 8:03 am

    How about this:

    paste "$@" | awk '{ printf("%s", $1); 
    for (i = 2; i < NF; i += 2) 
           printf(" %s", $i); printf "\n"; 
    }'
    

    This assumes that you don’t run into a limit with paste (check how many open files it can have). The "$@" notation means ‘all the arguments given, exactly as given’. The awk script simply prints $1 from each line of pasted output, followed by the even-numbered columns; followed by a newline. It doesn’t validate that the odd-numbered columns all match; it would perhaps be sensible to do so, and you could code a vaguely similar loop to do so in awk. It also doesn’t check that the number of fields on this line is the same as the number on the previous line; that’s another reasonable check. But this does do the whole job in one pass over all the files – for an essentially arbitrary list of files.


    I have 100 input files — how do I use this code to open up these files?

    You put my original answer in a script ‘filter-data’; you invoke the script with the 101 file names generated by seq. The paste command pastes all 101 files together; the awk command selects the columns you are interested in.

    filter-data $(seq --format="0_%g.dat" 0 6 600)
    

    The seq command with the format will list you 101 file names; these are the 101 files that will be pasted.

    You could even do without the filter-data script:

    paste $(seq --format="0_%g.dat" 0 6 600) | awk '{ printf("%s", $1); 
    for (i = 2; i < NF; i += 2) 
    printf(" %s", $i); printf "\n"; 
    }'
    

    I’d probably go with the more general script as the main script, and if need be I’d create a ‘one-liner’ that invokes the main script with the specific set of arguments currently of interest.

    The other key point which might be a stumbling block: paste is not limited to 2 files only; it can paste as many files as you can have open (give or take about 3).

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

Sidebar

Related Questions

I'm using Amazon EC2 with a Fedora 8 Core AMI. I have an EBS
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
I'm using g++ on fedora linux 13. I'm just practicing some exercises from my
I am using the easy eclipse on fedora Linux system. I have to configure
My same BASH script is working in Fedora/CentOS. But I am testing one Android
Hi I am using Fedora 10 linux. I have created a .spec file now
Hi I am using Fedora 10 linux. I have created an rpm for my
I have installed Fedora 14 on Windows XP using VMware with NAT as ethernet
I am Using Fedora 10, I would like to organize my files and folders?
I'm relatively new to Perl, writing some XML parsing scripts. I have done two

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.