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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:20:02+00:00 2026-05-30T23:20:02+00:00

I have a file which looks like this: 1 2 AA 4 5 AA

  • 0

I have a file which looks like this:

1 
2
AA 
4
5
AA BB
7
8
AA BB CC
10
11
AA BB CC DD

I am using awk to extract only every nth line where n=3.

>>awk 'NR%3==0' /input/file_foo >> output/file_foobar

The output is appearing in a single line as:

AA AA BB AA BB CC AA BB CC DD

…..and so on

I want it to appear as:

AA 
AA BB 
AA BB CC 
AA BB CC DD 

I tried using \n, printf with \n, and so on but it doesn’t work as I expect. Please advise.

  • 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-30T23:20:03+00:00Added an answer on May 30, 2026 at 11:20 pm

    A verbose way,

    awk '{ if (NR%3==0) { print $0}  }'
    

    Also you can use {printf("%s\n\n", $0)} too. if single \n does not work.

    If it still does not work you might need to check the line terminator. It may not be proper. Use the RS variable in awk to separate on the unusual line terminator.

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

Sidebar

Related Questions

I have got 1 file which looks like this COMPANY=xyz system.employee[0].Name=shayam system.employee[0].Age=26 system.employee[0].sex=Male system.employee[1].Name=ram
I have an index.html file which looks like this (the rest is omitted), <ul
I have an auto-generated file which looks something like this... static void do_SomeFunc1(void* parameter)
I have a yaml file which looks like this: --- date: 25-01-2010 version: 0.1
I have a Jamroot file which looks a bit like this; project foo ;
I have usercontrols which inherit a base class which looks like this: BasePage.cs: using
i have a text file which looks like this: random useless text <!-- this
I have a table with 3 columns which looks like this: File User Rating
I have an XML file which looks like this : <?xml version=1.0 encoding=UTF-8?> <resultset
Say I have an XML file which looks like this: <?xml version=1.0 encoding=UTF-8?> <Project

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.