Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Favorites infavorites:mine
infavorites:1234
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with Search options user 148566

Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

15
votes
A small extract from man bash: ${parameter:offset:length} Substring Expansion. Expands to up to length characters of the value of parameter starting at the character specified …
answered Apr 11 '16 by Ralph Rönnquist
1
vote
In the function, var2 is not declared local, and therefore it is "global", which means that the value it has at the end of the function will be the value it has after the call of the function. Said d …
answered Apr 12 '16 by Ralph Rönnquist
2
votes
Apparently bash is particular about the interpretation of a command line, where it discovers variable assignments before evaluating used variables. Basically a variable assignment requires the name pa …
answered Dec 8 '18 by Ralph Rönnquist
1
vote
sed -e 's/\([[:alpha:]]*,\)/\n\1\n/g' | grep ,
answered Feb 17 '16 by Ralph Rönnquist
1
vote
This might be a one-liner for you awk -F, 'n==""||n>$1{n=$1}{while(n!=$1){print n++}}{print;n++}' < input > output though it's not much different to what you had before, except the "protection" for …
answered Feb 16 by Ralph Rönnquist
1
vote
You might be happy enough just collating the "words", then pass them through the ``which` command. Perhaps like the following: cat $SCRIPT | tr -c '[[:alnum:]-_]' '\\n' | sort -u | xargs which The …
answered Jun 2 '16 by Ralph Rönnquist
2
votes
You can use the split command to run a "filter" upon successive chunks of a file, and write a filter using cmp, echo, and true to gain a newline for every successful match, then use wc for counting th …
answered Apr 12 '16 by Ralph Rönnquist
1
vote
I suppose the trick is to use -3t for the first pr, and then also add -w200 (or so) to avoid that the last column gets clipped. More generally, if you have N matrices, you'd use pr -${N}t -w $((N*W)) …
answered May 31 '16 by Ralph Rönnquist
2
votes
One perhaps not ideal way is to do alias exit=return, which then makes the second.sh exits do script return instead, with the code as given. This of course doesn't cut through nesting of functions lik …
answered Mar 9 '16 by Ralph Rönnquist
4
votes
Ok, with file names occurring in matching pairs, you could use the following: for f in words/*/*1.txt ; do awk -f corpus_vs_flexion.awk "$f" "${f%1.txt}2.txt" ; done The "${f%1.txt}2.txt" phrase sa …
answered Feb 29 '16 by Ralph Rönnquist
1
vote
Assuming the regular filename format as given, where the date is the last part before the extension, and it's immediately preceded by an underscore, plus that the extension is always .txt, you could u …
answered Mar 2 '16 by Ralph Rönnquist
0
votes
I'm using a bash function like the following function Xowner() { for pid in $(ps -houid --ppid $(ps -hoppid $(pgrep X))) ; do [ "$pid" = "0" ] && continue id -n -u $pid br …
answered Sep 27 '17 by Ralph Rönnquist
1
vote
Something like the following script, using gawk #!/bin/bash gawk -F, 'tbl[$1]!=""{$2=tbl[$1];OFS=",";print;next}{tbl[$1]=$2;}' $1 $2 You pass in the two files with the token file first. This assume …
answered Jan 23 '17 by Ralph Rönnquist
2
votes
Given the irregular choices of which rows to accumulate, it's hard to device a more generic solution, and it ends up as cherry picking, like the following: sed 's/row[0-9]*//;/^$/d' file | pr -2t -w …
answered Jun 4 '16 by Ralph Rönnquist