Skip to content

Tag: shell

escape one variable but not the other in awk

I’m facing a problem with awk in Linux. I would like to do make this script work : The problem here is that I want the variable “var” to be interpreted (it works) and the variable $OTHERVAR not to be interpreted, and this I what I can’t manage to do. In the end, I want to do this: I ha…

Split file into multiple when special char met

I have a main file as following : My final goal is to create a file that will containt only block that contains a specific string, for example if that string would be lines then I would have an output file like this : To reach my objective, I first try to split my main file into subfiles by bock

Group the consecutive numbers in shell

In shell, how to group the numbers in $foo as 1-3,6-8,11,13-17 Answer As an alternative, you can use this awk command: Now run it as: Here is an one-liner for doing the same: In this awk command we keep 2 variables: p for storing previous line’s number s for storing start of the range that need to be pr…