0

I try to print lines of a text which begin with a # I need only these lines, but not the ones with [[:whitespace:]]#

$ cat text.txt
# no whitespace in front of #
   # 3 whitespace in front of #
  # tab in front of #
$ cat text.sh
#!/bin/bash
TEXT=text.txt
Sub=2     # required for the case-statement I have to perform in the real script

while read LINE ; do
  case $Sub:$LINE in
    2:"# "*)        printf "%s\n" "$LINE" ;;
  esac
done < "$TEXT"

$ ./text.sh
# no whitespace in front of #
# 3 whitespace in front of #     <<< the 3 whitespaces are gone
# tab in front of #              <<< the tab is also gone
Gjiaffaar
  • 21
  • 2
  • See [BashFAQ/001](https://mywiki.wooledge.org/BashFAQ/001), and the duplicate. – Benjamin W. Oct 27 '21 at 10:21
  • Many thanks Benjamin, it did not came to my mind that the IFS in combination with read is the cause of my problem. So I was continuously searching the wrong posts. – Gjiaffaar Oct 28 '21 at 12:01

0 Answers0