For our school assignment, we have to implement input/output redirection. I managed to get the input and output redirection work, but I am facing an issue with append redirection. I am using testfile.txt: When the user types ls >> testfile.txt, I expect the output from ls to be added to the testfile. At this moment, the test lines get replaced
Tag: shell
Are there any solutions to this command(shell code) problem
I have some shell codes looks like: but, get an error “-bash: syntax error near unexpected token `(‘” which i can’t fix it. I do know the pipeline command can also do it well. likes but actually I wish to do something in the loops like change the global value and the pipeline didn’t work. Answer The correct syntax for
Reverse sort 3rd numeric column in file
In bash shell scripting, I have users.txt file. sort -t: -k 3n users.txt gives me This is ok. But I need 3rd column which contain only phone number in reverse order i.e. descending order. How to achieve that? I need like Answer You could add an r (short for “reverse”) to the order column specification:
Running bash script on multiple shells
So I was trying to create a script on bash shell, I came to know that the script doesn’t run on ksh or dash shells. So my question is how you make a script to run on all 3 (bash, dash & ksh) shells. Answer In order to write a script that is guaranteed to be portable between the various
find: combining multiple “-exec” statements not working with toybox / Android?
I am trying to figure this out on an Android phone running Oreo / 8.0, with toybox 0.7.3-android. I am trying to get a list of files inside a folder and their respective mtime. I am running this command: or In both cases I am only getting the result from the first invocation of “stat”. Am I overseeing something or
replace in text with a var with some new lines
I have a var $MY_VAR which contains some new lines: And a file my_file.txt with a value that has to be replaced: I try to replace it using: That results into the following error: Answer I finally found a totally different solution by removing the value to replace and split my file into two parts: my_file_part1.txt and my_file_part2.txt which are
shell script to change directory to the tail result path
I’m using Tail to an error happen on the log lines like: and this gives results like: So what I do manually is to change the path using cd: Is there any script to change directory automatically? As I run another manual script to change file names for the files contained in /003217899/, those like /003217899/ are happening many times
Looking to remove a set of characters from a .txt file
I am looking for a way to remove the content from one .txt file based on the other. For example, I have a file.txt with 2000 character that are random and not sorted. I have another file importantfile.txt with 2016 characters that have the same characters that file.txt has as well as 16 other characters randomly placed in. Is there
Only accept 4 character long, decimal numbers as user input for read
I am writing a small script to easily capture weights, which are taken from user input with read -p. I want all captured weights to be 4 characters long, decimal numbers in the format XX.X. For example 30.2 kg. How can I make sure users can only input decimal numbers in that format? Thank you for your help. Answer One
Linux script to check if DNS have the same IP like the one next to it in the same list
I’ve got a list of DNS and IP adresses in this format: DNS IP DNS IP DNS IP And I need to do a script which do dig +short DNS and check if it has the same IP as the one next to it, and that with all the document. The idea is that if it’s the same, it returns