File 1: File 2: My desired output: I am trying to implement this using bash or Python. In python I tried: In bash I was thinking of using grep but grep will give the output that matches the entire line but this is not the case here. Any ideas? Answer This is what works finally.
Tag: bash
possible missing library when running cmake
I am trying to install a program on my machine (running Linux), but I get the following error when I run make: What is wrong, am I missing a library? Answer The problem is that the Makefile uses bash specific syntax (|&) but the commands are executed by /bin/sh, which does not point to /bin/bash. On my co…
bash script – executing find command gives no output
I’m a total noob at bash so this is most likely a syntax error, but I could not find anything that worked for my syntax in my searches. From terminal, running find . -name “*g*” results in However, running this bash script called grepdir.sh from terminal as grepdir.sh . “*g*” res…
How to add more than 1 number in a loop in Bash script?
So I have this loop: I want to know how I can add 10 every time the loop repeats instead of adding 1. So I want the loop to look something like this: 110 120 130 140 and keep going until it reaches the limit or stopped! Thanks Answer Simply change ++ to += 10
Awk asking combine two files
I have combined two different files with Same Key by AWK command. And In case there is no key match compare to File1 and File2 then just put “ttt” instead. I have below AWK command. Example Combine File1 File2 Then Expected result My AWK Command Show I already tried to do few way like below But lo…
“less” consumes lots of RAM for a piped output on gzipped file, why?
Excuse me for useless cat and echo upfront, but while running less on a ~2GB .gz file I’m seeing ~25GB of RAM getting consumed (despite the output being piped into awk and consumed there): I expected above to complete without any need for RAM, but to my surprise here is how it looked like ~2.5h later (b…
Merge two lines into one and add character
I’v got a output like: I need to merge the strings and add symbol “R” betwen them like: How i can do it? Thanks Update. Sorry. Here is the comand Here is the output: I need output like: Answer
What is a better way to read each line in a file in linux?
Hi all, I want to read each line in a file and then make a whole url to do some thing. The above scripts worked, but what is a better way to read file line by line? Thanks. Answer This is a nice example of the useless use of cat, simply use IO redirection: The use of -r in read
Merge multiple files preserving the original sequence in unix
I have multiple (more than 100) text files in the directory such as The contents of the file are name of some variables like files_1_100.txt contains some variables names between 1 to 100 Similarly files_201_300.txt contains some variables between 101 to 200 and files_1001_1100.txt as I can merge them using t…
BASH: check for amount of memory installed on a system as sanity check
As part of a bash install script, I’d like the script to do a sanity check that the target machine has at least a given amount of memory installed. Note that I’m NOT specifically worried about how much memory is currently used or allocated or available – for my purposes the existance of more…