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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:21:40+00:00 2026-05-27T11:21:40+00:00

i have some data files, and i need to pull some info out. i’d

  • 0

i have some data files, and i need to pull some info out. i’d like to use a single awk script to get data out, so i can suck some data into bash arrays.

for this, let’s assume i need the following (1-indexed):
– i need awk to print column one on lines 2, 3, and 4
– i need awk to print columns 1, 2, and 3 on lines 8 and over. but i want all of the column ones printed before the column twos, and the column twos before the column threes.

using the following data example:

abc
def
ghi
jkl
mno
1a1
2b2
11 22 33 44
55 66 77 88
99 00 12 13
14 15 16 17

i would want awk to print the string:

def ghi jkl 11 55 99 14 22 66 00 15 33 77 12 16

i created the following, which i thought would work, but i am getting an error saying “END bocks must have an action part”.

awk '
BEGIN {i=0;}
{
   if ((NR >= 2) && (NR <= 4))
      print $1;
   if (NR >= 8)
   {
      col1_arr[i] = $1;
      col2_arr[i] = $2;
      col3_arr[i] = $3;
      i++;
   }
}
END
{
   for (j = 0; j < i; j++)
       print col1_arr[j];
   for (j = 0; j < i; j++)
       print col2_arr[j];
   for (j = 0; j < i; j++)
       print col3_arr[j];
}' /path/to/my/file

thanks ahead of time.

  • 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-27T11:21:41+00:00Added an answer on May 27, 2026 at 11:21 am

    This should work –

    awk '
    BEGIN{i=0;}
    NR>=2 && NR<=4 {printf $1" "} 
    NR >=8 {col1[i]=$1;col2[i]=$2;col3[i]=$3;i++;} 
    END{for (i=0;i<=NR-8;i++) printf col1[i]" "; for(i=0;i<=NR-8;i++) printf col2[i]" ";for (i=0;i<=NR-8;i++) printf col3[i]" "}' INPUT_FILE
    
    
    [jaypal:~/Temp] cat data
    abc
    def
    ghi
    jkl
    mno
    1a1
    2b2
    11 22 33 44
    55 66 77 88
    99 00 12 13
    14 15 16 17
    
    [jaypal:~/Temp] awk '
    BEGIN{i=0;}
    NR>=2 && NR<=4 {printf $1" "} 
    NR >=8 {col1[i]=$1;col2[i]=$2;col3[i]=$3;i++;} 
    END{for (i=0;i<=NR-8;i++) printf col1[i]" "; for(i=0;i<=NR-8;i++) printf col2[i]" ";for (i=0;i<=NR-8;i++) printf col3[i]" "}' data
    def ghi jkl 11 55 99 14 22 66 00 15 33 77 12 16
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data files that I need to install together with my application
We have some very large data files (5 gig to 1TB) where we need
I need to have some mechanism to backup and restore some data files from
I have been trying to strip out some data from HTML files. I have
I have a php script that I'm trying to pull some data from a
I have some data files to import into a database with some unique delimiters:
I have some code which handles data files and reports an error when it
I have some xml data contained in three files (Database.xml, Participants.xml, and ConditionTokens.xml). I
I have to read data from some files and insert the data into different
I have two files (f1 and f2) containing some text (or binary data). How

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.