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…
Tag: bash
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
Linux – add creation Date or DateTime in the name of the file
I have a file on a Linux server which is created automatically. I would like to create a script which will automatically rename the file after it is created on the server, so it will add date or datetime information For example: Thank you! Answer Try this: Here is the manpage of date where you can find the di…
Bash – Move last word in line to beginning of line
I need to move (in a text file) the last word on a line to the beginning of that line. From This: To This: Answer With GNU sed: Output: (2007) I Am Legend (1987) RoboCop (2001) Shrek To edit file “in place”:
How can I read the files from a tar command into an array using BASH?
Using a BASH script, how can I execute a tar command and read the output (the list of files) into an array? I’ve tried a number of things, including: I’ve tried with and without the backquote (grave accent) and I’ve tried using t as an option on the tar.gz file. I was trying to accomplish th…
What’s the easiest way to use the output paths from a git command in a subsequent git command?
I far too frequently use the mouse to do things like this: I know that some git commands accept wildcards, and this mitigates this problem somewhat, but I’m wondering if there is a way do specifically reference pathspecs, etc. from previous commands. How can I run commands like this without using the mo…
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