LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-22-2012, 12:08 PM   #1
threezerous
Member
 
Registered: Jul 2009
Posts: 96

Rep: Reputation: 16
What is \s* in awk programming


Trying out some awk scripts and cannot figure out from results what \s* stands for.

I ran the following two commands and I get the same output in both the cases
cat InFile | awk '/\s*(\w+\s)/'
cat InFile | awk '/(\w+\s)/'

The contents of InFile are (obtained from another discussion in this forum)

how now
now is the time for
now
holy cow
the quick brown fox
jumped over
the candlestick

The output I get from both the scripts above is
now is the time for
the candlestick

Thanks in advance for any help
 
Old 08-22-2012, 12:43 PM   #2
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by threezerous View Post
... cannot figure out from results what \s* stands for.
Google is your friend. Do a Google search on
Code:
awk "\s"
and you will get many hits. This one ...
http://www.gnu.org/software/gawk/man...Operators.html
... came up first on my screen. It tells:
Quote:
\s Matches any whitespace character. Think of it as shorthand for [[:space:]].
Daniel B. Martin
 
1 members found this post helpful.
Old 08-22-2012, 12:44 PM   #3
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
The \s refers to a "character class" containing whitespace. (For instance: spaces, tabs.)

The * is a "quantifier" that matches zero or more times the character that immediately precedes it.

Thus, \s* could be interpreted in plain English as match whitespace zero or more times.

----------

Note that your use of cat(1) in the examples is unnecessary. The awk(1) program can take its input file as an argument, a la:
Code:
$ awk '/baz/{ print }' boo.txt
----------

Finally, if that doesn't answer it, what is your question, exactly?

Last edited by anomie; 08-22-2012 at 12:46 PM.
 
1 members found this post helpful.
Old 08-22-2012, 01:51 PM   #4
threezerous
Member
 
Registered: Jul 2009
Posts: 96

Original Poster
Rep: Reputation: 16
Thank you Daniel and Anomie.

Anomie: My question was exactly that and your post did answer it. Thank you also for giving a simpler way to provide the input file.
Daniel: I di search google before posting this, but I was searching for awk /\s* and there were many results returned, none of which really spoke about /s. I guess I could have tweaked the search parameter a bit more.

As you might have guessed, I am just starting on awk programming and not a very good question this is.

Thanks much.
 
Old 08-24-2012, 12:12 AM   #5
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
http://www.gnu.org/software/gawk/manual/
http://www.gnu.org/software/gawk/manual/gawk.html

If you are serious about awk, download, read and underst and how awk works and the features.
With this download, you have the current gawk manual as a reference.

It has got many samples too.

OK

Last edited by AnanthaP; 08-24-2012 at 12:18 AM.
 
  


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
Programming in AWK hjorge_2001 Linux - Newbie 2 04-25-2012 11:12 AM
[SOLVED] The AWK programming Language huaihaizi3 Programming 4 03-22-2011 10:04 AM
[SOLVED] Help in using 'awk' programming........ apanimesh061 Programming 8 11-21-2010 09:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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