Skip to content

Tag: grep

grep to read exact data from text file

I have file test1.txt file, i am trying to read variable which is enclosed in double quotes and starting with hyphen for eg: “-color”. i trying to use this grep command cat test1.txt | grep getParm | sed ‘s/getParm(/ /;s/&/ /;s/,/ /;s/”/ /g’ | awk ‘{print $3}’ , w…

Bash script how to display matched words in custom order

The following is the output of the command ads2 cls create However, I’m trying to extract the value of name and state for each node, save them in a variable and display them in the following order: Till now i, with the help of this so much powerful learning site, could extract the values of name and sta…

grep -r –include not works but –exclude works

In bash, What’s the problem? Answer You are using curly braces incorrectly. The correct syntax would look like (Notice also the addition of the missing file name argument . at the end.) You can see what’s going wrong by putting an echo in front and examining what the shell expands the braces to.

linux grep match a subset of files from a previous match

I am needing pipe this result: to another grep: ie. “files that extend Some_Critical_Class that also have function init()” If there is a way to do it in one operation in grep, that would be great, but I’d also like to see the how the piping is done to improve my programming in *nix (which is…

Trying to find empty files in other user home directory

I want to search for empty files inside the home directory of the user “adam” for example. Now i don’t know the right path for that user, so I need to get it from /etc/passwd with the following command: Output: /home/adam (for example) Then executing this command to find the empty files. Is …

bash – print regex captured groups

I have a file.xml so composed: I need to extract the following information: mayor_and_minor_release_number –> 1.0 patch_number –> 13 suffix –> -alpha I’ve thought the cleanest way to achieve that is by mean of a regex with grep command: I’ve checked with regex101 the cor…

Extracting a set of characters for a column in a txt file

I have a bed file (what is a txt file formed by columns separated by tabs). The fourth column has a name followed by numbers. Using the command line (Linux), I would like to get these names without repetition. A provided an example below. This is my file: My list should look like this: Could please help me wi…