I have these files: 100-1.jpg 100-2.jpg 200-1.jpg 200-2.jpg I want these to be transferred to specific folder based on filename 100/100-1.jpg 100/100-2.jpg 200/200-1.jpg 200/200-2.jpg How do I do this? What I have tried so far how do I know I cut the string before the dash e.g 200-1 to 200 and store in a variable? so I can do it
Tag: shell
How to “grep” in array with dot “.” precisely?
I’m trying to check if the user input $1 exist in an array. And here is my code: What I expect is only “aaa.bbb.ccc” or “ccc.ddd.aaa” can be found. However, in this case, like “aaa” or “ccc” can also pass the validation. Seems like the dot is not treated as part of the string. Should I use regex or other
How to get Date Month values in linux date command as integers to work on
I want to convert date and month as integers. for example. if the current date as per the command “Date +%m-%d-%y” output, is this 09-11-17 Then I am storing the $cur_day will give me 11 and $cur_month will give me 09. I want to do some operations on the month as 09. like i want to print all the numbers
truncate shell command output from last line matching a string until EOF
I would like to truncate the output of a shell script and only print the part between the last line matching a string/regex and EOF. E.g when running letsencrypt certbot renew –post-hook “service apache2 reload; service nginx reload” I get something like Now what I want to have is everything after the last ——- line, so the desired result would
edit the only lines which matches some word
I have to search a file for lines with some specific words and edit these lines as follows. The other lines should remain the same. For example: to be modified to: Can any one please help how to use AWK to achieve this. Regards Answer awk solution: Explanation: When brz or jp matches, save last field in last, remove last
get all aliases in linux shell
How to list all aliases defined in a shell. Like the command below to list all files/folders in a directory I have defined some alias in ~/.bashrc i want to list all that command Answer Are you wondering if you have a UNIX alias already set for a specific command? You can find it easily by issuing this on the
Shell script to edit and add a entry in file
Could any one help me to add entry at the end of the line. This is linux os. Below is the contents of the file /boot/grub2/grub.cfg I need to add entry at the end of the line “text1” and “text2”. after edit my file should look like: Answer With sed expression:
Listing files with numeric names
How do I list files that have only numeric names e.g I have tried ls -l [0-9]* but this seems to bring all file names that start with a digit and can have anything in their name after a digit. Answer First, turn on Bash’s extglob option: Then use this pattern: Read more about extended pattern matching in the Bash
Shell param doesn’t pass with command
I use the following code to execute shell command, the issue is that when I put it as parameter which I should get from user it doesn’t work but If I put it hard-coded it works. Working Not working In the not working version which I do cat to param I see the value printed OK, what could I miss
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 shell into a .pyc file to