I made this code I want to compare two folders and the folder are arguments to the command line.. it should be something like this : ./script.sh dir1 dir2 But i have this eror : **./director.sh: line 29: `$1′: not a valid identifier ** I want to count the file from dir1 who is argument to the command li…
Tag: bash
time option doesn’t work
I tried to measure execution time and format it with this command: But such command works: I tried to determine where another time is located, but all showes to /usr/bin/time or or How to define where another time is located? Answer Users of the bash shell need to use an explicit path in order to run the exte…
Using awk to trim away parts of a text file outside 2 patterns
I’d like an elegant awk solution to edit the lines in a file. So far I’ve only managed to complete the task using 2 sed commands and 1 awk command. Each file is composed of a header of indeterminate length, followed by the data I want to capture, then a footer which always starts with the same str…
How can I create a patch to delete a folder and create new folder using diff?
For example I have two directories say old and new. The directory old has a sub-directory abc and the directory new has a sub-directory cde. I tried creating patch by using I got following output in file.patch: and when I tried to patch the file I got following error: When I try to create patch by using: I ge…
manipulate column fields for clean representation
Hi I have data in txt file in following format I want to only extract IP address and bytes field, so final result should be Also at the end i want to group by bytes (3rd column) by first field. to get : Any help ? thanks Answer If you want to consider awk: EDIT: Based on comments below:
Using shell commands with boot2docker
I have created a boot2docker VirtualBox instance, I can SSH into it OK but then when I try and run any commands such as bash I get Pretty sure I’m missing something really simple but can’t see what. Looking in /bin it doesn’t look to contain bash I’m pretty new to the *nix world so be …
I’ve found a way to use find -exec to cp multiple files all in one line like xargs, but I’m not sure exactly how it works
I’ve been working with find -exec and find | xargs for the past few hours exploring and experimenting, and now I’ve found a variation of the command that I haven’t seen anywhere else. For example this find command to get all files in the child subdirectories and copy them to the current dire…
Using bc as daemon in BASH shell from awk
In BASH environment I can communicate with bc program using fifo. But in awk I can write but no read with getline function. How can I read from “/dev/fd/4” in awk. My awk version is: mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan Thanks Laci Continued: I did some further experiment and I su…
How to make a return from a child function cause a return to the parent function?
I have a parent function and child function: How to make the return 1 (of the child) cause a return in the parent and then avoid the execute the remaining child calls? without adding a check of the returned value after each child call like this Answer There is a solution other than set -e and || return ItR…
Remove Files older than 3 years
I need to remove any file in the directory that is older than 2 years old. It is very important that I keep the newest files and delete the old files. I have searched and found this. Can I just multiply the number? Is there a way to add a switch that will print the file name to the screen