Skip to content

Tag: bash

“cat a | cat b” ignoring contents of a

The formal definition of pipe states that the STDOUT of the left file will be immediately piped to the STDIN of the right file.I have two files, hello.txt and human.txt. cat hello.txt returns Hello and cat human.txt returns I am human.Now if I do cat hello.txt | cat human.txt, shouldn’t that return Hell…

Find out the shell which was used to run the process in linux?

I recently got stuck in a situation where I need to find out the name of the shell for a list of process (or for a single process, using pid). Is there a way we can find it out (preferably using ps and grep command). Answer Since you know that the processes have been started from a shell, you just

BASH syntax error at line 1: `then’ unmatched

Hi, I am having issues with this particular loop and couldn’t find a solution to it, any ideas why? Answer If you run the code through shellcheck and correct the errors which it shows (except for one problematic warning), the code will become: The code still seems to have issues, one of which is that it…

Pass argument to awk inside do loop

I have a large number of tab-separated text files containing a score I’m interested in in the second column: test_score_1.txt test_score_2.txt I want to check if I have Titles with a score smaller than a number I define. The following code defines my score in the script and works: check_score_1 If I try…

Bash sort ignore first 5 lines

I’m having trouble ignoring the first 5 lines of my file while sorting the rest. My current command sorts the entire file by the second item, however I need to skip the first 5 “header” lines. I need read it and write it to the same file. Current Command Example Answer This sorts lines 6 and…

How to remove only the last word from a file

I created the following Perl one-liner in order to remove a word from a file This Perl also escapes special characters such as @ or $ or *, so every word that contains a special character will removed from the file. How to change the Perl syntax in order to delete only the last matched word from a file and

linux sed reads whole file when only editing first line

I am currently working with CSV files that can be 10’s of GB in size, and need to edit the headers dynamically depending on the use case. For this I am using: which has the desired effect of only editing the headers, but can take upwards of 10 seconds to complete. I imagine this is because the whole fil…

Handling Dates in FTP

Here is my ftp script The output of this script is: I googled and seen some posts regarding dates but all provided formats not worked for me. Please advise Thanks in anticipation Answer through to FTP, which can include executing commands, substituting variables, and the like. That is to say, instead of writi…

ssh + ssh is stuck on remote machine [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. This question does not appear to be about programming within the scope defined in the help center. Closed 6 years ago. Improve this question simple script in order to perform reboot on Linux machine after run…