Barefoot IO
  • Member for 5 years, 11 months
  • Last seen more than 5 years ago
What core kernel-level IPC mechanisms exist in Linux?
3 votes

From IPC mechanisms on Linux - Introduction: The Linux kernel provides the following IPC mechanisms: Signals Anonymous Pipes Named Pipes or FIFOs SysV Message Queues POSIX Message Queues SysV ...

View answer
Finding number of child processes of a particular process
Accepted answer
4 votes

ps -eo ppid= | grep -Fwc $pid If your grep does not support -w: ps -eo ppid= | tr -d '[:blank:]' | grep -Fxc $pid or ps -eo ppid= | awk '$1==ppid {++i} END {print i+0}' ppid=$pid or (clobbering ...

View answer
sed delete all besides first and last line of many files
0 votes

Gawk is a much better tool for this task than sed. Repurposing the original approach's find-xargs pipeline and using the same output nomenclature: find . -type f -name \*.txt -printf "%f\0" | xargs -...

View answer
Splitting file based on last digit of first column in UNIX
3 votes

In a single pass: awk ' NR == 1 { for (i=1; i<=10; i++) print > sprintf("sales-%02d.csv", i) } NR > 1 { print > sprintf("sales-%02d.csv", $1%10+1) } ' data

View answer
Parent process always printing output after child
Accepted answer
2 votes

As @AndrewHenle commented, depending on the system to schedule your processes in a specific sequence is unsafe and unjustified. Even when the scheduling appears to be consistent (as in your case), ...

View answer
POSIX print function definition
1 votes

No. At least, not to my knowledge. -f is an extension to POSIX export. POSIX set (and bash set in POSIX mode) also excludes function definitions.

View answer
How to search efficiently for a list of strings in a big code directory
1 votes

A portable, POSIX-compliant translation of Stéphane Chazelas' gawk approach: find . -type f -exec cat {} + | awk ' FNR==NR {keys[tolower($0)]; n++; next} { s = tolower($0) for ...

View answer
How to merge one directory into other?
0 votes

Your intent is unclear to me, but perhaps what you need is a symbolic link in /etc. If so, consult man ln.

View answer
Why doesn't strace report that the parent shell fork() a child process before execve() a command?
4 votes

The fork in question is part of the mechanism which launches strace; it has concluded by the time tracing begins.

View answer
dd show 'raw' progress while piping output
0 votes

Here's a single script that should accomplish the goal: ( dd if=/some/lvm bs=512K & pid_dd=$! while :; do sleep 1 kill -USR1 $pid_dd ...

View answer
I want to grep out a text string from many files, how can I run a loop for this
1 votes

An ed alternative, because you only live once: for f in *.xyz; do printf '%s\n' ';g/END/d\' "w ${f%.xyz}_s.xyz" q | ed -s "$f" done Filename caveats: Filenames cannot begin with !, otherwise ...

View answer
Using literal empty curly braces {} inside sed command from find -exec
Accepted answer
7 votes

In this case, you can work around find's exec grammar by capturing a brace expression and using a back reference in the replacement text: $ cat f1 f2 f1: hello{}a f2: hello{}a $ find . -type f -exec ...

View answer
bash: tee eats newlines after exec
1 votes

tee is most likely being killed by the signal before receiving the newline.

View answer
Why is set-o errexit breaking this read/heredoc expression?
Accepted answer
17 votes

read returns a non-zero exit status if it doesn't find a delimiter. With the delimiter set to the empty string, it uses the NUL byte as a delimiter, and those usually aren't found in text files.

View answer
How can I replace rows containing ONLY number ' 0' with blank rows using AWK?
3 votes

After editing your post, it appears that the lines in your sample input do not contain "ONLY" the zero. They contain many spaces and a zero. If this is the case, with awk: awk 'NF==1 && $1=="...

View answer
Is it a sane approach to "back up" the $IFS variable?
Accepted answer
11 votes

You can save and assign to IFS as needed. There is nothing wrong with doing so. It's not uncommon to save its value for restoration subsequent to a temporary, expeditious modification, like your array ...

View answer
Bash script stopped recognizing substitute file
1 votes

I assume that init_db.sh and db_schema.sh are in the same directory. The combination of cd and a file name that's relative to the current working directory, ./files/functions/db_schema.sh, suggests ...

View answer
Counting the occurences of character in a filesystem tree
1 votes

My guess is that the problematic machine's grep does not support -o. If this is the case, then your command line is generating an error message each time find execs grep. However, with standard error ...

View answer
Shell with parameters order of entry is the issue
1 votes

Because your while-loop unconditionally shifts twice, even when the option doesn't take an argument. The second command line's ordering is merely getting lucky.

View answer
How to add a newline to the end of a file?
20 votes

A simple, portable, POSIX-compliant way to add an absent, final newline to a would be text file: [ -n "$(tail -c1 file)" ] && echo >> file This approach does not need to read the ...

View answer
Does vi silently add a newline (LF) at the end of file?
52 votes

POSIX requires this behavior, so it's not in any way unusual. From the POSIX vi manual: INPUT FILES See the INPUT FILES section of the ex command for a description of the input files supported by the ...

View answer
How can I do a binary search of a text file for a specific character string?
3 votes

This could be locale related. If so, using the C (aka POSIX) locale, where characters are bytes, may work: LC_ALL=C grep --color='auto' -P -n "[\x80-\xFF]{2,10}" record.txt

View answer
Grep is not matching non-ascii characters
Accepted answer
4 votes

e4 75 is indeed an illegal utf8 sequence. In utf8, a byte with the highest nibble equal to 0xe introduces a three byte sequence. The second byte of such a sequence cannot be 0x75, because the high ...

View answer
exit status of command is different when it is run via strace
Accepted answer
3 votes

I am not familiar with this executable, but my guess is that it needs to run with privilege (probably suid root or similar). strace -f cannot run such a process with privilege unless strace itself is ...

View answer
Grep line after/before -A/-B substitution in AIX
1 votes

ed may provide a simple way to complete this task. If we can assume that there is only a single match, then an alternative to your pipeline, using ed and eliminating the unnecessary cat and secondary ...

View answer
Combining text across contiguous lines keyed alike?
1 votes

Advanced knowledge of each block's length spares us from the minor complication of dealing with a boundary condition which would otherwise require an END block of replicated functionality. I do not ...

View answer
Matching n letter filename with ls
7 votes

ls -q | grep -Ex '[[:alnum:]]{5}'

View answer
Parse file with Awk only when first row matches pattern
2 votes

Assuming a simple, comma-delimited file where every comma is a delimiter (some csv files may have quoted commas that ought not to be treated as field seperators), the following prints every line ...

View answer
How to escape shell metacharacters automatically with `find` command?
2 votes

The following is a relatively straightforward, POSIX-compliant pipeline. It scans the hierarchy twice, first for directories and then for *.xml regular files. A blank line between scans signals AWK of ...

View answer
Sort files by highest number in filename
1 votes

If the files are in the current working directory and their names conform to the samples (a single dash which precedes a number), the following POSIX-compliant pipeline should work: ls | sort -t- -k1,...

View answer