Regex to identify word in second position on a line

I am interested in finding a regex to find a word in second position on a line. The word in question is
I tried the following PERL EXPRESSION but it did not work:

[^[:word:]]  
or
^\W  

But both gave Null results
I am giving below a Sample file:

  =delegate
   =film
  =slant
  =dissolve
  =grate
   =avow
   =spur
  =heave
  =shrug
   =mistime
   =orient
   =double
  =preface
   =cockle

I would like the REGEX to single out all lines where the word occurs in second position.
Many thanks for the help.

I am somewhat at a handicap because of the script. Maybe time I learned. :slight_smile: Anyway, maybe the following explanations will solve for you:

[^[:word:]] means a single character that is NOT a word character.
^[[:word:]] means a single word character at start of line.

^\W means a NON-word character at beginning of line.
^\w means a word character at beginning of line.

Maybe too simplistic an approach, but try

$ awk '$2==""' file
  =delegate
  =slant
  =dissolve
  =grate
  =heave
  =shrug
   =mistime
   =double
  =preface
   =cockle

Many thanks the Awk script worked, but I am still curious about finding a regex to identify the position of a word in a string

Try:

perl -ne 'print if /^(\S+)\s(\s|$)/' 

or

perl -ne 'print if /^((\S+)\s+){1}(\s|$)/' 

The word boundary \b does not seem to fly here..

\b will work with the -CD command-line switch. But, then you'll need to be careful about what \w and \W will match.

If the environment variables are correctly set, I believe that use locale; or -Mlocale would inform perl on how to interpret character classes.

Please do not mistake me for a competent perl hacker.

EDIT: I was just skimming through perllocale. Wow. What a mess. Long story short, my suggestion may not be safe.

Regards,
Alister

$
$ perl -lne 'print if /^\S+\s+/' file
  =delegate
  =slant
  =dissolve
  =grate
  =heave
  =shrug
   =mistime
   =double
  =preface
   =cockle
$
$

Many thanks to all who replied and for your efforts to find a solution to a regex issue which has been hassling me since quite some time. Both AWK and PERL scripts worked perfectly. For me it was a learning experience in the intricacies of regex.