Skip to content
Advertisement

Tag: string

Split string in ksh

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.

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

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

Advertisement