LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 10-06-2017, 02:55 PM   #1
Springs
Member
 
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
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Is this what you want?
Code:
cat foo
asdhS01ashd
easyS03hard
twodigitS33after

awk -F'S[0-9][0-9]' '{print $1}' foo
asdh
easy
twodigit
 
Old 10-06-2017, 03:59 PM   #3
Springs
Member
 
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
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:15 AM.

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