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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:34:15+00:00 2026-05-25T17:34:15+00:00

How to redirect records to different output files based on a value in one

  • 0

How to redirect records to different output files based on a value in one of the columns in a file using nawk/awk?..

chethan RA
Ramesh  RA
Sachin  RA
Gundaa  DI
dravid  DI
Suresh  SE

So I want to redirect RA records to one file, DI records to another file and SE records to another file. Value in Second column can be anything need not be RA, DI or SE. So based on different values in second column, records need to be redirected to different files..

  • 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-25T17:34:16+00:00Added an answer on May 25, 2026 at 5:34 pm

    You could try something like this:

    4.1.10(4)-release$ cat infile 
    chethan RA 
    Ramesh RA 
    Sachin RA 
    Gundaa DI 
    dravid DI 
    Suresh SE
    4.1.10(4)-release$ awk '{
    >   f = $2 ".txt"
    >   print > f
    >   }' infile
    4.1.10(4)-release$ head *txt
    ==> DI.txt <==
    Gundaa DI 
    dravid DI 
    
    ==> RA.txt <==
    chethan RA 
    Ramesh RA 
    Sachin RA 
    
    ==> SE.txt <==
    Suresh SE
    

    Consider that some awk implementations can open a limited number of files at a time.
    If that’s the case you’ll need more code, something like this:

    [corrected, see comments below]

    awk '{
      if (f) close(f)
      f = $2 ".txt"
      print >> f
      }' infile
    

    The latter will be far less efficient.

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

Sidebar

Related Questions

To redirect (and append) stdout and stderr to a file, while also displaying it
I'm trying to redirect all requests to my domain to another domain using mod_rewrite
I am fetching records for a user based on his UserId as a JsonResult...
My question involves a few different active records class Respondent < ActiveRecord::Base has_many :phone_numbers,
Chrome caches DNS records and tends to ignore changes to the hosts file after
I am trying to delete multiple records using check boxes. I've loaded each check
I am developing a complex form that updates several records of one model at
I'm pulling records from the database and created a PHP file to execute when
I have a sub domain that I want to redirect to a different location
After updating or creating a record I use url helper to redirect to the

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.