I got a string as follow : What would be the best way to convert it in seconds without using date ? I tried something like this that sounded pretty nice but no luck : Any idea is welcome, I just can’t use date -d to make conversion as it is not present on the system I am working on.
Tag: string
Sorting an array of dates in bash
I want to sort an array of dates. Example format: “2017-11-13_07-55-40” or Year-Month-Date_Hour-Minute-Second Answer Since your dates are already in YYYY-MM-DD-HH-MM-SS format, you can use numeric sort: To store output in another array use:
string to long, not giving me the correct answer
I am trying to convert number stored in the c string to long int. But I am not getting the expected output: Output : 821493369 gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) Can you please advise what am I doing wrong here? Thanks. Answer In addition to using long long, you can use exact width types from stdint.h. For instance,
Trimming string up to certain characters in Bash
I’m trying to make a bash script that will tell me the latest stable version of the Linux kernel. The problem is that, while I can remove everything after certain characters, I don’t seem to be able to delete everything prior to certain characters. Somehow the output “ignores” the wget=${wget##.tar.xz”>} line. Answer You’re trying remove the longest match of the
How to use content of variable in bash to pass to find in script?
In a bash script I’m trying to use the content of a variable to be used as options for the find command: The aim is to set proper access rights as for what ever reason quite some files (such as pictures or office documents) are marked executable. So in reality the script above has several arrays with file extensions concatenated,
How do I locate a string in a binary file? (No, not the strings command.)
I know about the very useful “strings” command. It will print all the printable strings in a binary file. But what I want is a command that will tell me the location (in bytes or whatever — I’ll take anything.) of a string in a binary file. Is there a way to get this in Linux? Answer The strings command
How can I recursively search for multiple patterns on linux?
I am trying to find files that include either of the following two patterns: By AND, I mean a logical and. I am using the following command: to check if a file has INTO and SELECT, but this returns the string if either one exists, but I need both. Answer If the patterns have to occur on the same line,
C segmentation fault on linux with strncmp
This works (‘Y’ must be single quotes): This gives segmentation fault: strncmp must be going off the deep end but not sure why since I’m passing a casted toupper() as (char *). Without the casting, same error. FYI user_input() is (N.B. vars are global): Thank you. Answer The return value of toupper is another character, not a pointer to a
Sorting of data in descending order
Allow me to clarify my query: I have a database with thousand of character strings, followed by some values (based on scoring matrix) There are equal values also present. I am trying to sort the data in descending order using: But the data is still disarranged. Also tried by adding -k argument. Is it possible that i could get the
Inserting strings to file names with different extensions
I have a number of files of different type in a directory: file, file0, file.txt, file.jpg etc. Some with extensions, some without. I want to rename files in a directory by inserting ‘final’ to them. So they would appear as: filefinal, file0final, filefinal.txt, filefinal.jpg etc. I imagine that to deal with the presence of files with and without extensions, I’ll