I have the following string in bash with length > 4 and I want to extract into str2 the 5 first charachter of str. So How to do it with bash? Answer Do use the expression So in this case: See other usages: Taken from: – wooledge.org – How can I use parameter expansion? How can I get substrings? How
Tag: bash
Cutting the column including size
I want to cut the column which include the size of files . I use ls -l to view info about files in current localization . I save info about file in txt file ls -l > info.txt , and now I want to cut the column including size . I do cat info.txt | cut -d” -f6 but i
File size in human readable format
Given the size of a file in bytes, I want to format it with IEC (binary) prefixes to 3 significant figures with trailing zeros, e.g. 1883954 becomes 1.80M. Floating-point arithmetic isn’t supported in bash, so I used awk instead. The problem is I don’t how to keep the trailing zeros. Current solution: (The files aren’t that big so I don’t
how to make SSH command execution to timeout
I have a program like this: In the above code, I am trying to SSH to the remote server, and tries to check if I can connect or not. I have few servers, which is password less is activated and few servers for which passwords are still not yet deactivated. So my concern, if there is a password, it will
search for files not accessed for x days
How can I find files in Linux that were not accessed for X days? I found that command, but it will show files that were viewed for the last x days: Answer Use -atime +60 to see files that have not been accessed within the last 60 days:
Display duplicate lines in two different files
I have two files and I would like to display the duplicate line. I tried this but it doesn’t work : cat id1.txt | while read id; do grep “$id” id2.txt; done I am wondering if there are any other way to display the duplicate lines in the file. Both of my 2 files contain list of ids. Thank you.
How to count number of tabs in each line using shell script?
I need to write a script to count the number of tabs in each line of a file and print the output to a text file (e.g., output.txt). How do I do this? Answer
Linux: Use parameter as file shortcut
Cheers everyone 🙂 I’m trying to make a linux script. This script shall be called with one parameter, a file stored in my home directory. I can’t seem to use So i have this variable $var1 and I want to save it in a file that does exist and its name is given in $1 Anyone help me please! Answer
inputrc file cannot be loaded [closed]
Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 10 years ago. Improve this question I just figured out we can create a ~/.inputrc file to define keyboard mappings. But I don’t know how to load it. I tried to source it but
Sending signals to a linux process and intercepting them
I have a following bash script: If run it and from other terminal send the SIGINT to it, it does nothing. I am using kill -2 pid where pid is the pid of the running script. If I hit CTRL+C (SIGINT) in terminal where the script is running it kills itself and writes the message. How come, it is not