Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-06-2017, 02:55 PM   #1
Registered: Apr 2008
Posts: 73

Rep: Reputation: 0
awk with a range of numbers?

hi all,

I'm currently using the below command to get the text before S01 in the filename thats listed in the txt file. what ideally need is to change the 01 so that it looks for any number say between 1 and 100 and still print out the text before it.

awk -F'S01' '{print $1}' file.txt

I don't know of another way. the above works if i change the S01 to another value. I've looked around online but none of the suggestions given seem to work for my requirements.

to confirm, the S01 doesnt change but the text before it does which is why i'm using it as a marker.

any ideas?
Old 10-06-2017, 03:23 PM   #2
Senior Member
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,039

Rep: Reputation: 1234Reputation: 1234Reputation: 1234Reputation: 1234Reputation: 1234Reputation: 1234Reputation: 1234Reputation: 1234Reputation: 1234
Is this what you want?
cat foo

awk -F'S[0-9][0-9]' '{print $1}' foo
Old 10-06-2017, 03:59 PM   #3
Registered: Apr 2008
Posts: 73

Original Poster
Rep: Reputation: 0
yes, exactly what i was after.

i swear i tried this or at least something similar and it didn't give the right response.

Thanks for the assistance


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to filter a text file based on a range of numbers in a specific column using awk nash-c Programming 20 03-24-2016 06:44 AM
[SOLVED] [GREP] range of numbers czezz Programming 13 09-24-2015 12:43 PM
[SOLVED] find the total of numbers that are higher than x in a text file with numbers (using awk??) Mike_V Programming 12 11-24-2010 09:51 AM
To get a range of prime numbers som_kurian Programming 12 11-18-2009 04:15 AM
Shell scripting - Random numbers within a range felixc Linux - Newbie 2 10-09-2005 05:41 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:04 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration