source_id
int64 1
74.7M
| question
stringlengths 0
40.2k
| response
stringlengths 0
111k
| metadata
dict |
---|---|---|---|
736,546 | I have a bit of an issue with the following command which extracts a tar file & prints how many files have been extracted every second: tar -xvf some_tar.tar -C a/directory | awk 'systime() > lasttime { lasttime = systime(); printf "%d files\n", NR; fflush(stdout) }' Even if the tar command fails, the awk command will still return 0, which is undesirable because it does not reflect that the tar command failed. How might I go about fixing this? | If you just want to see if any command in the pipeline failed, set the pipefail option. It's supported in ksh, zsh and Busybox (at least), in addition to Bash. With that option set, the exit status of a pipeline is the leftmost non-zero exit status returned by the commands involved. $ set -o pipefail$ (exit 123) | true$ echo $?123 Or with the pipeline just in a conditional (this should say "it failed"): set -o pipefailif false | true; then echo it succeededelse echo it failedfi | {
"score": 4,
"source": [
"https://unix.stackexchange.com/questions/736546",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/321024/"
]
} |
736,678 | I have a paste command like this paste -d , file1.csv file2.csv file3.csv And file2.csv contains numbers like this 0.20.33390.111111 I want the values in file2.csv having 3 decimals like this: 0.2000.3340.111 For one value this is working: printf "%.3f" "0.3339" -> 0.334 But for multiple values in file2.csv this is not working: paste -d , file1.csv <(printf %s "%.3f" "$(< file2.csv)") file3.csv Maybe there is a good solution? | You're close; you just need to tell printf to zero-pad to the right of the decimal point: $ cat 736678.txt0.20.33390.111111$ for value in $( cat 736678.txt ); do printf "%.3f\n" "$value"; done0.2000.3340.111 The format string %.3f means "a floating-point number with precisely three decimal places to the right of the point". | {
"score": 4,
"source": [
"https://unix.stackexchange.com/questions/736678",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/558210/"
]
} |
736,706 | I have two files that both have the field "tumor id". Both are comma delimited. I need to add a field that is uniquely in file 2 to file 1, and I want to add the lines of the field according to their corresponding strings in "tumor id". An example format is: File 1 Tumor_ID, Chromosome, start, end,xxxxx, 2, 12, 13,xxxxx, 3, 45, 46,xxxxx, 3, 48, 49xxxxx, 3, 51, 52,nnnnn, 5, 55, 59,nnnnn, 5, 57, 58,lllll, 11, 13, 14,lllll, 12, 16, 17,eeeee, 2, 51, 52,zzzzz, 9, 1000, 101, File 2 Patient_No., Tumor_ID, Normal_ID, 4, xxxxx, hhhhh, 5, nnnnn, aaaaa, 8, lllll, ddddd, 7, eeeee, ggggg, 3, zzzzz, nnnnn, How would I create a new field in File 1 (say, -f15) and assign the Normal_ID values from File 2 to their corresponding Tumor_ID values in the newly created file 1 field? Does my question make sense? | You're close; you just need to tell printf to zero-pad to the right of the decimal point: $ cat 736678.txt0.20.33390.111111$ for value in $( cat 736678.txt ); do printf "%.3f\n" "$value"; done0.2000.3340.111 The format string %.3f means "a floating-point number with precisely three decimal places to the right of the point". | {
"score": 4,
"source": [
"https://unix.stackexchange.com/questions/736706",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/477496/"
]
} |
736,748 | I am trying to do the same for https://github.com/eneshecan/whatsapp-for-linux/releases as is described here: Download and install latest deb package from github via terminal but cant get it to work, it seems because the URL is not in the source but only seen in the browser?can anyone help?I just need the full URL as a string so I can download and install the deb file | You're close; you just need to tell printf to zero-pad to the right of the decimal point: $ cat 736678.txt0.20.33390.111111$ for value in $( cat 736678.txt ); do printf "%.3f\n" "$value"; done0.2000.3340.111 The format string %.3f means "a floating-point number with precisely three decimal places to the right of the point". | {
"score": 4,
"source": [
"https://unix.stackexchange.com/questions/736748",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/390472/"
]
} |
736,833 | I'm running a headless Raspberry Pi, and would like to convert the console/terminal output to a single jpeg or video stream. For example: capture the output of pbytop every few seconds and stream it to a website using mjpeg (or through ffmpeg as a h264 stream). I'm just stuck on the jpeg/video capturing part, streaming that media out of the pi to the website fine. The closest I've managed to get is: ssh into pi start tmux start pbytop inside tmux ssh into pi from a second virtual terminal capture the tmux pane into a txt file: tmux capture-pane -J -p -t %0 > /tmp/pane-plain-text.txt tmux capture-pane -e -J -p -t %0 > /tmp/pane-with-colors.txt I can then cat /tmp/pane-with-colours.txt and it looks perfect, however that's still just a txt file with a bunch of color escape sequences in it, not an image. Before I go down the "ascii to image" path can someone please point me in a better direction? I feel like there's something I could do with a combination of /dev/fb0 and extracting that to a stream using ffmpeg -f fbdev -i /dev/fb0 etc... | You're close; you just need to tell printf to zero-pad to the right of the decimal point: $ cat 736678.txt0.20.33390.111111$ for value in $( cat 736678.txt ); do printf "%.3f\n" "$value"; done0.2000.3340.111 The format string %.3f means "a floating-point number with precisely three decimal places to the right of the point". | {
"score": 4,
"source": [
"https://unix.stackexchange.com/questions/736833",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/374245/"
]
} |
737,072 | This is probably in the zsh manual, apologies for being lazy and asking it here. There seems to be something special about :t in zsh, as witnessed by the following example. % x=foo% echo $x:barfoo:bar% echo $x:toadfoooad The behavior with $x:bar is the expected one, but :t seems to backspace. Can someone direct me to the appropriate section in the manual that discusses this? Thanks! | :t is a Modifier t [ digits ] Remove all leading pathname components, leaving the final component (tail). This works like ‘ basename ’. Any trailing slashesare first removed. Decimal digits are handled as described above for(h), but in this case that number of trailing components is preservedinstead of the default 1; 0 is treated the same as 1. % x=/foo/bar/baz% echo $x:toad bazoad% echo $x:tbaz% echo ${x:t2}bar/baz ( :t , from csh was there from the start in 1990 while the :t2 variant was added in 2019 first available in version 5.8). | {
"score": 5,
"source": [
"https://unix.stackexchange.com/questions/737072",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/562376/"
]
} |
737,311 | I want to rename .gz files according to names in separate txt-file.I have a map with .gz files with the names: trooper10.gztrooper11.gz trooper12.gzetc. and I have a separate txt-file with the wanted name(s) in in the first column and the .gz-names in the other column (tab-separated). B25 trooper10C76 trooper11A87_2 trooper12 So the files should be renamed like this B25.gzC76.gzA87_2.gz I tried for i in *.gz; doline=$(grep -x -m 1 -- "${i}" /path_to_txtfile/list_names.txt) But im not sure how to grep the corresponding column in the txt-file. Since there is many gz-files I want to ask if there is any way to this? | Yes, you just start by reading the file instead of getting the gz files from the file system: while IFS=$'\t' read -r newName oldName; do mv -- "$oldName".gz "$newName.gz"done < names_file | {
"score": 4,
"source": [
"https://unix.stackexchange.com/questions/737311",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/562660/"
]
} |
738,424 | I've never seen ncdu do this. What's the matter with the red S and extra size columns? This is a Windows root (NTFS, mounted with ntfs-3g ), so I assume it has something to do with NTFS. But the sizes in the extra column make no sense at all, nor can I find any documentation of what it means. Interestingly only directories have the second size column, but not all of them have it. And I find no pattern between those that do and those that don't. Places I've researched: man ncdu Google | This is explained in the shared links section of the Ncdu 2 introductory post. It is a way of handling directory size discrepancies caused by hard links sharing content outside the directory: when “S” is displayed, the second column displays the amount of shared data in the directory, and when “U” is displayed, the second column displays the amount of unique data in the directory. The size shown with “S” is disk space that won’t be freed if the directory is deleted, because it is also “held” by files outside the directory. | {
"score": 5,
"source": [
"https://unix.stackexchange.com/questions/738424",
"https://unix.stackexchange.com",
"https://unix.stackexchange.com/users/375550/"
]
} |