Replace spaces with commas from one file and send the output to another file.
tr -s '[:blank:]' ', ' < input.txt > output.txt |
It’s perfect for creating a comma delimited file for importing to Excel.
cloud engineer
Replace spaces with commas from one file and send the output to another file.
tr -s '[:blank:]' ', ' < input.txt > output.txt |
tr -s '[:blank:]' ', ' < input.txt > output.txt
It’s perfect for creating a comma delimited file for importing to Excel.
How to sort files in Bash.
Display contents
$ cat file.txt
bbb
aaa
ccc
kkk
uuu
ppp |
$ cat file.txt bbb aaa ccc kkk uuu ppp
Sort
$ sort file.txt
aaa
bbb
ccc
kkk
ppp
uuu |
$ sort file.txt aaa bbb ccc kkk ppp uuu
Sort in place
$ sort -o file.txt file.txt $ cat file.txt aaa bbb ccc kkk ppp uuu |
$ sort -o file.txt file.txt $ cat file.txt aaa bbb ccc kkk ppp uuu
Here’s the script that looks mounts with stale file handles and removes them.
#!/bin/bash file='/tmp/stale.txt' df -h | grep Stale > $file sed -i -e 's/df: ‘/'""'/g' $file sed -i -e 's/’: Stale file handle/'""'/g' $file while IFS= read -r line; do echo 'unmounting '$line umount $line done < $file |
#!/bin/bash file='/tmp/stale.txt' df -h | grep Stale > $file sed -i -e 's/df: ‘/'""'/g' $file sed -i -e 's/’: Stale file handle/'""'/g' $file while IFS= read -r line; do echo 'unmounting '$line umount $line done < $file
Check mounted file systems using df. Displaying different options.
df df -h df -Th |
df df -h df -Th
To get rid tmpfs, run this.
df -Th| grep -Ev '(udev|tmpfs)' |
df -Th| grep -Ev '(udev|tmpfs)'
How to do search and replace in Vim.
Search for “foo” and replace it with “bar” in the current line. Use :s
:s/foo/bar/g |
:s/foo/bar/g
Search for “foo” and replace it with “bar” in the entire document. Use :%s
:%s/foo/bar/g |
:%s/foo/bar/g
You can also pipe instead of forward slash. Useful if your search contains a /.
:%s|foo/|bar|g |
:%s|foo/|bar|g