• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Search

file

Bash Replace Spaces with a Comma

May 8, 2023

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.

Filed Under: Linux Tagged With: bash, commas, file, input, output, replace, spaces

Bash Sort Files

April 10, 2023

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

Filed Under: Linux Tagged With: bash, file, sort

Cleanup Stale CVS Snapshots

August 30, 2022

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

Filed Under: Linux Tagged With: bash, cvs, file, handles, snapshots, stale

Check Mounted File Systems

July 28, 2022

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)'

Filed Under: Linux Tagged With: check, df, file, mounts, systems, tmpfs

Vi Search and Replace

April 3, 2022

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

Filed Under: Linux Tagged With: entire, file, replace, search, vim

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Go to Next Page »
  • Home
  • About
  • Search

Copyright © 2023