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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:15:36+00:00 2026-05-28T19:15:36+00:00

I have a file structured as record list, where field separator is \t. I

  • 0

I have a file structured as record list, where field separator is \t.
I want to extract only records where the second field is a number from 1 to 9, but my awk script doesn’t work.
The awk script is

cat file |awk -v FS="\t" '$2 ~ /[0-9]{1}/ {print $0;}'

or this

cat file |awk -v FS="\t" '$2 ~ /.{1}/ {print $0;}'  #because the second fields of my file have  all second fields as number

Why these sscript don’t work? Isn’t regex a good regex?

  • 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-28T19:15:38+00:00Added an answer on May 28, 2026 at 7:15 pm

    Update

    Even with the interval {1}, you are still going to match a field like 23 because the 2 matches a single number. What you really want to use are anchors and forget about intervals:

    awk '$2 ~ /^[0-9]$/{print}' FS="\t" file
    

    The problem is the use of intervals {1}. awk less than version 4 doesn’t support intervals. gawk on the other hand will if you add the following flag: --re-interval

    Try this:

    awk --re-interval '$2 ~ /[0-9]{1}/{print}' FS="\t" file
    

    Some other things to note:

    1. Built in vars such as FS can be assigned at the end without the need for -v
    2. You can use just print rather than print $0 as that is its default behavior
    3. Useless use of cat. awk can take a file as an argument, use that instead
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a plist structured string, that get dynamically (not from the file
I have this file structure: folderIWantStuffIn/ - old_stuff Now I want to add some
I have a file with the structure like so: http://gamedev.pastebin.com/8iESYTVY but it's much bigger
Ok, so I currently have a binary file containing an unknown number of structs
I have an inventory record XML file to store the quantity of each item.
I have an export functionality that reads data from DB (entire records) and writes
I have an incoming XML file with a list structure: <list> <listItem> <name>elementOne</name> <value>elementOneValue</name>
I have very simply structured data which is currently stored in a home-brew file
I want to parse a file based on a record layout provided in another
I have to encrypt a list containing three fields for each record (a tag,

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.