Skip to content

Tag: bash

Partially replace string using ‘sed’ shell command

I need to delete the <#> in the following pattern: Outputs should be like: I was trying to do this sed ‘s/(vdd1[a-z]*).<[0-9]>/1/’ file1 > file2 But it gives me “vdd1” all the way. How can I do it correctly? Answer The dot . after the paren is matching the letter after t…

Is space considered a metacharacter in Bash?

I have searched for the list of metacharacters in Bash but space is not enlisted. I wonder if I’m right by assuming that space is the “token separation character” in Bash, since it not only works as such with Shell programs or builtins but also when creating an array through compound assignm…

While loop to test if files with a given pattern exist in bash

I want to check with a file loop like this, if files with a given pattern exist: If more files like 12aaa-Stock.txt, 34aaa-Stock.txt are present I have a message error like binary operator expected. Answer You can work around this by using a for-loop, e.g,. As long as there are no files found, the for-loop ha…

Bash – Remove line based on length of first word

I need to delete lines (in a text file) that start with a word that is less than 4 characters. In the example The quick brown fox gets removed since the first word is only three characters in length. Before: After: Answer preprocess.awk output

How to make pipe run sequentially

Specs Don’t think this should make a difference but I’ll include it anyway GNU bash, version 3.2.51 Premise So say i have a pipe with multiple parts, how can I prevent part of the pipe running before the previous part is finished. Example In the below examples I will try to display the issue Outpu…

AWK remove duplicate line based on two conditions

I am trying to remove duplicates based on the value of the 2nd field. The lower value of the 2nd field should be retained, any line with repeated 1st field and higher 2nd field should be removed. This is an example of my raw data: Here is how it should be: So far, based on this post: I came up