Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Or tr -d '[:alpha:][:digit].' for a different Q :) Commented Dec 31, 2017 at 6:41
  • @steeldriver Thanks for your quick answer. I have trying to build my command based on your exemple: NAME1=$(sed -n '1p' 's/[^[:alpha:][:digit:][:blanck:][:punct:].]//g' textfile and on a debian, it return me this following error message: command.sh: 1: [:sed: unexpected operator, i don't think i have forget something.. Commented Dec 31, 2017 at 10:37
  • @Rom, Try name=$(sed -n '1p;s/[^[:alpha:][:digit:][:blank:][:punct:].]//g' textfile);echo "$name" Commented Dec 31, 2017 at 12:49
  • @Rom what are you actually trying to do? what is the purpose of the -n 1p that you have added? Do you want to print the first line regardless? If you just want to remove all characters except those given from all lines, you should be able to use the command I posted without modification. Commented Dec 31, 2017 at 13:28
  • Ok thanks it has works fine, but my first actual command to check if a certain line (for exemple the second or the third) is writed is this followed: if [ sed -n "1p" file.txt ]; then....., have u a better idea ? :) Commented Dec 31, 2017 at 17:01