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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:06:07+00:00 2026-05-27T01:06:07+00:00

I have a tab separated file with 16 fields. Can i use awk to

  • 0

I have a tab separated file with 16 fields. Can i use awk to conditionally alter one one or fields and print the whole line as the output? e.g., depending on value in the first field, i want to say add a specific number to field 4 and so on. But as a output i have to print the whole line. If yes, i would like to know how.

  • 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-27T01:06:08+00:00Added an answer on May 27, 2026 at 1:06 am

    Yes, here’s an approach:

    awk '$1 == "ALTER" { $5=$5+5 } 1'
    

    With etuardu’s sample file, this produces

    ALTER xx yy zz 15 10
    NOALT aa bb cc 20 20
    ALTER 11 22 33 35 30
    

    Here’s how it works. There are two cases, expressed as awk patterns and actions. In the first, the pattern is a test of the first field to see if it equals "ALTER", invoking the action that modifies the fifth field if the pattern evaluates to true. The second pattern is that final 1; it’s always true, so the implicit print action is performed.

    One quirk with this solution: the field separators read in the input need not be those in the output. With the simple form above, the field separators from the inputs are taken to be whitespace, while single spaces are written to the output; set FS and OFS to specific values if that isn’t what you want. However, only lines where a field is changed will have the new field separators, so a null op like ‘$1=$1’ will force all records to be rebuilt (this is a convenient way to change field separators, by only using $1=$1).

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

Sidebar

Related Questions

I have a text file which is tab separated. They can be quite big
I have a tab separated file How can I input this file into a
I have a huge tab separated file which I want to sort on its
I have a tab-separated data file with a little over 2 million lines and
I have a Unicode file (UTF-16 FFFE little-endian BOM) which contains rows of tab-separated
I have 12 columns separated by a tab. How can I join them side-by-side?
I would like to sort a file on more fields. A sample tab separated
I have a tab separated text file in the format id | field 1
I have a tab separated text file after executing some command in powershell i
I have a simple tab-separated text file that I want Ruby to read every

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.