Remove sections of audio in SoX - wav

What's the easiest way to remove the specified sections of a wav file using SoX? Right now I use the trim command to break up the file and then concatenate the parts. However, that seems a little tedious and backwards since trim takes a section of audio and copies it to a new file, so I have to trim the opposite of the the sections that I specify to remove, and then concatenate those. Any help appreciated, thanks!

This is ugly but... try:
sox "|sox in.wav -p trim 0 start" "|sox in.wav -p trim length" out.wav
Where start is the the offset of the removing area and length is the
number of seconds to remove
Example: to remove between 30s and 50s:
sox "|sox in.wav -p trim 0 30" "|sox in.wav -p trim 20" out.wav
Update -- a better solution:
sox in.wav out.wav trim 0 =start =end
Example: to remove between 30s and 50s:
sox in.wav out.wav trim 0 =30 =50

Related

Remove rows inside txt file - unix

i need to remove some particular rows in a txt files considering a particular value. In particular i need to delete all the rows that cointain this syntax.
Row to deleted
0311MUX 31.03.2020
In the report i have rows like below one that should not be deleted since after mux i have a code.
0311MUX23453 31.03.2020
Could you please help me on this?
Thank you
Something like
printf '%s\n' 'g/^0311MUX[[:space:]]/d' w | ed -s file.txt
Will delete all rows from the file starting with that string followed by whitespace (to avoid deleting your other row with 0311MUX as a prefix).
Or
perl -ni -e 'print unless /^0311MUX\b/' file.txt

clear terminal screen but keep visual spacing

When I want to provide a visual break after a long list of output lines from a command I normally run clear so that the terminal will clear the screen, put my prompt back at 0,0 while also keeping the history (vs reset).
The problem is that when I scroll up, the terminal is now back to the long lines of output, without any kind of break in history.
I had the idea of "echo'ing a screen's worth of empty lines" by doing yes '' | head -n $(tput lines), but then my cursor is at the bottom of the screen. So I try to run clear but it seems to remove the empty lines. I also tried tput cup 0 0 but that also removes the empty lines (I guess by "reverting" my screen's worth of empty lines).
I can force the empty lines by printing any character with yes instead of the empty string, or I can print some character/message at the end of the empty lines. But now I'm adding garbage.
The only thing I've been able to get to work is:
yes '' | head -n $(($(tput lines) * 2))
tput cup 0 0
Is there another way or is this my only option?
Essentially yes - you can express the script in various ways, but most terminals don't allow one aspect which could be used to improve your script: when scrolling up, they don't move blank lines into the scrollbar. So you can't (for example) do it like this:
tput cup $(tput lines)
tput indn $(($(tput lines) * 2))
tput cup 0 0
tput ed
since the blank lines that you would expect from indn (index) are ignored.

special character removal 'sed'

I'm facing an issue where I'm getting some special characters in my file at the beggining; a snap of the same below:
^#<9b>200931350515,test1,910,420032400825443
^#<9a>200931350515,test1,910,420032400825443
^#<9d>200931746996,test2,910,420031390086807
I'm using the following command to remove anything other than numbers in first column:
sed 's/^[^0-9]*//g' file.dat
No success on that. The file is created btw during a fastexport from Teradata, the process adds some special characters by itself during extract.
Any idea on the command?
If you want to remove any non-ASCII characters anywhere in a line, you can use tr.
tr -d '\000\200-\377' <file >file.new
Using perl
perl -lne 'print /\d+,.*/g'
200931350515,test1,910,420032400825443
200931350515,test1,910,420032400825443
200931746996,test2,910,420031390086807
matches only digits up to the first comma and then everything else.
sed is to big gun for such a small problem,
use cut to remove the beginning of each line:
cut -b 2- file.dat
Where 2- is the range of bytes you want to retain, I'm not sure how many such strange characters you have there, so I would experiment with 1-, 2-, 3-, 4-, 5-, etc.
It looks like the number of characters that should be removed is constant across all line. To remove a fixed number of characters from the beginning of each line, you could simply do
$ sed 's/^.....//' input >output
Adjust the number of dots to fit your need.

unix split skip first n of lines

I have a rather large file I need to split. However, I don't need the first 1000 lines. I would like to start the split at line 1001 and then continue to split the file by 1000. I know how to split by 1000, that is no problem.
CODE:
split --lines=1000 *.txt
However, I want to skip the first 1000 lines. Is there any way to do this?
Use tail -n +1001 to get lines starting from 1001st line:
cat *.txt | tail -n +1001 | split --lines=1000
#JDE876 : We can even get the desired output using perl one liner
perl -ne "print if $. > 1000" file

Delete newline in Vim

Is there a way to delete the newline at the end of a line in Vim, so that the next line is appended to the current line?
For example:
Evaluator<T>():
_bestPos(){
}
I'd like to put this all on one line without copying lines and pasting them into the previous one. It seems like I should be able to put my cursor to the end of each line, press a key, and have the next line jump onto the same one the cursor is on.
End result:
Evaluator<T>(): _bestPos(){ }
Is this possible in Vim?
If you are on the first line, pressing (upper case) J will join that line and the next line together, removing the newline. You can also combine this with a count, so pressing 3J will combine all 3 lines together.
Certainly. Vim recognizes the \n character as a newline, so you can just search and replace.
In command mode type:
:%s/\n/
While on the upper line in normal mode, hit Shift+j.
You can prepend a count too, so 3J on the top line would join all those lines together.
As other answers mentioned, (upper case) J and search + replace for \n can be used generally to strip newline characters and to concatenate lines.
But in order to get rid of the trailing newline character in the last line, you need to do this in Vim:
:set noendofline binary
:w
J deletes extra leading spacing (if any), joining lines with a single space. (With some exceptions: after /[.!?]$/, two spaces may be inserted; before /^\s*)/, no spaces are inserted.)
If you don't want that behavior, gJ simply removes the newline and doesn't do anything clever with spaces at all.
set backspace=indent,eol,start
in your .vimrc will allow you to use backspace and delete on \n (newline) in insert mode.
set whichwrap+=<,>,h,l,[,]
will allow you to delete the previous LF in normal mode with X (when in col 1).
All of the following assume that your cursor is on the first line:
Using normal mappings:
3Shift+J
Using Ex commands:
:,+2j
Which is an abbreviation of
:.,.+2 join
Which can also be entered by the following shortcut:
3:j
An even shorter Ex command:
:j3
It probably depends on your settings, but I usually do this with A<delete>
Where A is append at the end of the line. It probably requires nocompatible mode :)
I would just press A (append to end of line, puts you into insert mode) on the line where you want to remove the newline and then press delete.
<CURSOR>Evaluator<T>():
_bestPos(){
}
cursor in first line
NOW, in NORMAL MODE do
shift+v
2j
shift+j
or
V2jJ
:normal V2jJ
if you don't mind using other shell tools,
tr -d "\n" < file >t && mv -f t file
sed -i.bak -e :a -e 'N;s/\n//;ba' file
awk '{printf "%s",$0 }' file >t && mv -f t file
The problem is that multiples char 0A (\n) that are invisible may accumulate.
Supose you want to clean up from line 100 to the end:
Typing ESC and : (terminal commander)
:110,$s/^\n//
In a vim script:
execute '110,$s/^\n//'
Explanation: from 110 till the end
search for lines that start with new line (are blank)
and remove them
A very slight improvement to TinkerTank's solution if you're just looking to quickly concatenate all the lines in a text file is to have something like this in your .vimrc:
nnoremap <leader>j :%s/\n/\ /g<CR>
This globally substitutes newlines with a space meaning you don't end up with the last word of a line being joined onto the first word of the next line. This works perfectly for my typical use-case.
If you're wanting to maintain deliberate paragraph breaks, V):join is probably the easiest solution.

Resources