I am in need of a listing of all files with a specific extension on a server. I need it to show the server hostname, file size, and absolute path of the file. or Almost get me there: joes_server 5473 /home/joe/pics/sunset.jpg 8522 /home/joe/pics/mountains.jpg I cannot figure out how to include the hostname on…
Tag: linux
Partially replace string using ‘sed’ shell command
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…
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…
bash order-of-operations in math context: Wrong value assigned
Given the linux shell code, Why does $b equal 2? I split the code into three steps: $b equals 1 this time, why? P.S. Neither a nor b is initialized. Answer Because you set b = a, then bash waits for last assigning of a. In b will be assigned same value as the value assigned to a. EDIT 1)
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…
ssh using R system() command
When I try to connect computer A to computer B using ssh and R’s system() command, I get an error: But if I enter the command in quotes into my Linux terminal (ssh root@Bs-ip-address) it works fine (ssh keys are set up for the correct user). How can I connect properly using R’s system() command? O…
dependency error in R package
Everytime I give the command for any package, in this case for ggplot2, I get this after a few minutes. I am missing something, but can’t figure out what. Thanks in advance! Answer You are on R 2.14. Please please PLEASE upgrade to something from the last few years — preferably from the current ye…
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”: