Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

how to print the line in case the first field start with Linux1

for example:

  echo Linux1_ver2  12542 kernel-update  |   awk '{if ($1 ~ Linux1 ) print $0;}'

the target is to print the line , while the first field start with Linux1

example of lines:

Linux1-new  36352 Version:true
Linux1-1625543  9847
Linux1:16254 8467563 

remark - space or TAB could be before the first filed

share|improve this question
up vote 6 down vote accepted

One way:

echo "Linux1_ver2  12542 kernel-update"  |  awk '$1 ~ /^ *Linux1/'
share|improve this answer
$1 and ^ are redundant. Your proposal doesn't cover tabs. – Hauke Laging Apr 17 '13 at 10:40

awk ignores leading blanks when assigning fields. The default command is print.

awk '$1 ~ /^Linux1/'

Is what you want.

share|improve this answer

This should work for this specific case.

awk '/^[[:blank:]]*Linux1/ {print}'
share|improve this answer
but if space is before Linux1 the it will no match – yael Apr 17 '13 at 10:27
@yael I made an edit to correct that. – Hauke Laging Apr 17 '13 at 10:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.