Skip to content

Tag: bash

extract multiple blocks of text to a new file

I need help extracting blocks of information from a single text file into new files or some form where I can manipulate the data from each block. Example: I need to be able to display and/or manipulate the variables (which I can do if I can isolate the right one). I don’t mind writing each one of these …

Using a compiled Python shell in Linux

Is it possible to use a “more complex” shell than just a single command shell? We have written a python shell that is a command loop, and it works fine in /etc/passwd like this: Of course the Python file has the shebang line for /usr/bin/python in it. However, we’d like to compile the Python…

JSON list (not object) to Bash array?

I’ve got a JSON list (the value of a key-value pair containing a list of items): [ “john”, “boris”, “joe”, “frank” ] How would I convert this to a bash array, so I can iterate over them? Answer Easy Case: Newline-Free Strings The simple approach is to use …

compare two comma separated strings and list the common values

How many I compare the two comma separated list (master and input) and list the common values among them (result) while preserving the order of elements in master list. For example: case1: case 2: case 3: This is what I tried: Answer Here is one awk-oneliner solution: Test with your 3 cases: Case 1 Case 2 Cas…

Sed/awk: Aligning words in a file

I have a file with the following structure: I want to add another item to the file, using sed or awk: etc. So my next item looks like this: The column values is jagged. How do I align my values to the left like for previous items? I can see 2 solutions here: To align the values while inserting them

Read the log files and get the entries between two dates

I want to extract some information from the access log file that matches a keyword and between two dates. For ex. I want to find log entries between two dates that contains text “passwd”. For now, I am using the following command but not getting the correct results: Date format is [22/Feb/2017:17:…

Linux shell script regex match

I have a text file. I want to get lines starting with specific format. I just want to get lines that have x/x/x format. x is a number. But this regex is not working. It is always giving no match : File is : Answer Don’t use bash if you can use a better tool: But if you have to