Skip to content

Instantly share code, notes, and snippets.

@ionvision
Created December 7, 2016 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ionvision/042a8ccc5ce58142473ce78d177f5e30 to your computer and use it in GitHub Desktop.
Save ionvision/042a8ccc5ce58142473ce78d177f5e30 to your computer and use it in GitHub Desktop.
Some useful bash/powershell commands
Bash:
========================
find ./ -type f -name "*"|xargs grep "encoding" > /home/xrong/Documents/VOC2010/VOCdevkit/VOC2010/file.list
sed -i '/encoding/'d `awk -F: '{print $1}' /home/xrong/Documents/VOC2010/VOCdevkit/VOC2010/file.list`
sed -i "s/oldstring/newstring/g" `grep oldstring -rl yourdir`
sed -i "s/www.bcak.com.cn/bcak.com.cn/g" `grep www.bcak.com.cn -rl /home`
perl -pi -e 's|ABCD|Linux|g' `find ./ -type f`
perl -pi -e 's| <object/>\n||g' `find ./ -type f`
Sort:
sort -t" " -k4nr 'Cell2ear.txt' > 'Cell2ear_sort.txt'
copy specific files
rsync -avm --include='*.csv' -f 'hide,! */' . /CSV
recursively merge all files under a root directory
Use find with two -exec options:
find $YOUR_DIR -iname '*.csv' -exec cat {} \; -exec echo \;
Edit: also, maybe if your CSVs have a header, instead of cat, you may use sed 1d to supress the first line:
find $YOUR_DIR -iname '*.csv' -exec sed 1d {} \; -exec echo \;
# FFmpeg extracts I-Frames
ffmpeg -ss 00:01:21.569 -i *.mp4 -t 00:00:36.572 -q:v 2 -vf select="eq(pict_type\,PICT_TYPE_I)" -vsync 0 %03d.jpg
-ss: start time
-t: duration
# recursively delete all files with specific name
find . -type f -name '*.o' -delete
# remove all blank lines for all files
perl -ni -e 'print unless /^$/' `find ./ -type f`
Powershell:
========================
Contents Retrival:
Get-Content .\in.txt | Where-Object {$_ -notmatch 'not'} | Set-Content out.txt
Delete multiple items with exceptions:
gci E:\Archive\Cell2earX -Recurse -Exclude @('*1.jpg', '*6.jpg') | ? { ! $_.PSIsContainer } | Remove-Item -Force
Rename multiple items recursively:
get-childitem *.jpg -recurse| rename-item -newname { $_.name -replace ".tm3",".mp3" }
Delete first line of a text file:
Get-ChildItem *.lb | ForEach-Object { (get-Content $_) | Where-Object {(1) -notcontains $_.ReadCount } | Set-Content -path $_ }
Select top 12491 lines
Get-ChildItem *.lb | ForEach-Object { (get-Content $_) | select -First 12491 | Set-Content -path $_ }
Sort text file by descending:
Get-Content .\file.txt | Sort-Object { [double]$_.split()[-1] } -Descending
Get-ChildItem *.lb | ForEach-Object { (Get-Content $_) | Sort-Object { [double]$_.split()[-1] } -Descending | Set-Content -path $_ }
Get-ChildItem * -recurse | Where-Object {$_.Attributes -ne "Directory"} |
ForEach-Object { (Get-Content $_) -replace
"cell2ear_neg","cell2ear" | Set-Content -path $_ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment