1

how to display lines which start with many pattern:

[*] 3 
[*] 4 
[*] 5 
[*] 6

Using sed command: sed '/[*]/!d' file i were able to display lines starting with [*]

so am looking to find lines which start with [*] 3 OR [*] 4 OR [*] 5

so how to handle it because there's one space before the digit as above input.

  • what are you exactly trying to do? To delete lines which only start with [*] without any following characters? – RomanPerekhrest Nov 18 '17 at 20:37
  • sorry i edited the question, wanna display lines start with [*] 3 OR [*] 4 OR [*] 5 – αԋɱҽԃ αмєяιcαη Nov 18 '17 at 20:39
  • @RomanPerekhrest if you don't mind, in case if i would like to remove [*] and spaces in lines, which sed command shall i use. – αԋɱҽԃ αмєяιcαη Nov 20 '17 at 16:38
  • here sed 's/^\[\*\][[:space:]]*//' file – RomanPerekhrest Nov 20 '17 at 17:38
  • @RomanPerekhrest i applied the command on file containing such of the following line [*] 111, 22, 33, 44 but it's print it out as 111, 22, 33, 44 but am looking to get the line as 111,22,33,44 – αԋɱҽԃ αмєяιcαη Nov 21 '17 at 12:37
2

Straight sed approach:

sed '/^\[\*\][[:space:]]*[0-9]/!d' file
|improve this answer|||||
  • @αԋɱҽԃαмєяιcαη, you're welcome – RomanPerekhrest Nov 18 '17 at 20:54
0
grep '^\[\*\] [3,4,5,6]' input.txt

or using range for numbers [3-6]

grep '^\[\*\] [3-6]' input.txt
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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