Showing posts with label File. Show all posts
Showing posts with label File. Show all posts

05 March 2025

How To Search And Replace String Across Multiple Files in Vim

https://irian.to/blogs/how-to-search-and-replace-string-across-multiple-files-in-vim

 

Perform substitution with macros and repeat it

While recording a macro, perform substitution on one file, and repeat the macros across all args.

Assuming the same folder structure and args, here is how it is done:

qq                                          // start macro in q register
%s/stringToBeReplaced/replacementString/ge  // the e flag tells vim to not throw an error if there is no match
:wnext                                      //important. This is similar to `:next`, but it also writes the current file
q                                           // stop macro
999@q                                       //repeat this macros either 999 times or to remaining files.

That's it!

08 March 2023

How to install .deb files on Ubuntu?

https://linuxconfig.org/install-deb-file-on-ubuntu-22-04-jammy-jellyfish-linux


$ sudo dpkg -i example.deb
 
If the package requires dependencies that aren’t already on your system, you will see 
this error in the terminal:
 
dpkg: error processing package 

Don’t fret, because we can install the required dependencies with a single command, 
assuming that they are available in Ubuntu’s package repository. Just run this command 
to install the dependencies: 

$ sudo apt install -f

22 August 2021

Can open Excel files locally but not from network

 

Can open Excel files locally but not from network

Problem: 

Can open Excel files locally but not from network

Solution:

File -> Options -> Trust Centre -> Trust Centre Settings -> Protected View.

Clear all the ticks. Click OK.



10 August 2021

How to read a file, which only contains a string, into Python, and then convert the string into a list?

 How to read a file, which only contains a string, into Python, and then convert the string into a list?


from pathlib import Path

txt = Path('filename.txt').read_text()

list_ = list(txt.split('; '))

27 July 2021

How to concatenate all the text files in a directory with Python?

 How to concatenate all the text files in a directory with Python?


https://stackoverflow.com/questions/13613336/python-concatenate-text-files

import glob2

filenames = glob2.glob('*.txt')  # list of all .txt files in the directory

with open('outfile.txt', 'w') as f:
    for file in filenames:
        with open(file) as infile:
            f.write(infile.read()+'\n')

09 July 2021

How to get lost files back resulting from running git add and git restore -s@ -SW?

 How to get lost files back resulting from running git add and git restore -s@ -SW?


Problem

suppose you ran

$ git add .

then you ran

$ git status

and saw that you have added some files which you did not want to add. 

(You did not run 

$ git commit

)

then you wanted to remove them from the index.

In haste, you ran 

$ git restore -s@ -SW

resulting in those files are gone away from your working tree (resulted from -W).

You want to get them back.

Solution:

Run

$ git fsck --cach --no-reflogs --lost-found --unreachable head

You will get a list of SHA1, which point to your lost files.

Then run

$ git show SHA1 > name_of_lost_file

one by one, every lost file will now be in your current work directory!


01 July 2021

How to find all the files containing the string 'abc' in the current directory and all the sub-directories

How to find all the files containing the string 'abc' in the current directory and all the sub-directories?


find . -type f | xargs fgrep '...'

20 June 2021

How to list all html files in a directory recursively sorted by file size?

 How to list all html files in a directory recursively sorted by file size?

$du -a -h | sort -nr | grep 'html' | less

Note:

1. '-a' means all files and directories, not just directories.

2. '-h' means human readable.

3. '-n' means numeric sort.

4. '-r' means recursive.

24 March 2021

How to redirect 'print' output to a file using python?

 How to redirect 'print' output to a file using python?




import sys

orig_stdout = sys.stdout
f = open('out.txt', 'w')
sys.stdout = f

for i in range(2):
    print 'i = ', i

sys.stdout = orig_stdout
f.close()

29 July 2019

How can I find out if a specific program is installed?

How can I find out if a specific program is installed?



scp [source file] [username]@[destination server]:.


scp cool_stuff.txt sanjeev@example.com:.


 Remember not to miss the colon and full stop at the end.

https://superuser.com/questions/850740/how-to-upload-local-file-to-server-through-linux-terminal






23 March 2018

How to associate .docx with Microsoft Word in Windows 10?

How to associate .docx with Microsoft Word in Windows 10?

Open 'File Explorer'.
Browse to the .docx file you want to open but failed.
Select it by clicking it.
Click 'Home' tab in the menu on the top.
Click the downward triangle beside 'Open'.
Click 'Choose another app'.
Click 'More apps ↓'.
If there is no 'Microsoft Word', then scroll down and click 'Look for another app on this PC'. An 'Open with...' dialogue box' pops up. Current path would be 'Windows (C:) > Program Files'.
Double-click 'Microsoft Office'.
Double-click 'Office14'.
Choose 'WINWORD.EXE'. Click 'Open' button. (Tick 'Always use this app to open .docx files'.)
Done.

08 March 2018

PowerPoint Won't open network files

PowerPoint Won't open network files

We can also try disable Protected View to see if it helps. To do this, please follow:
1. Open a PowerPoint file.
2. Click File > Options > Trust Center > Trust Center Settings.
3. Click Protected View from the left panel.
4. Clear all the three check boxes and click OK.
If above doesn't work, please also try testing with a new Windows user profile.

11 July 2017

It saves to a .prn file when I want to print a .pdf file

It saves to a .prn file when I want to print a .pdf file to SHARP MX-3640N printer

Solution:

Open the .pdf file you want to print.
Click File/Print.
Click Advanced. There is no tick mark against 'Print to File'.
Tick it. Click OK. Click Print. 'Print to File' popup box appears. Click 'Cancel'.

Click File/Print/Advanced again. Clear the tick against 'Print to File'. Click OK.
Click Print. It prints successfully.

08 December 2014

How to copy Chinese and English texts from a photo PDF file?

Adobe Acrobat
Tools | Text Recognition | In this file | Edit | Priamary OCR Language,

Choose Chinese, then English will also be OK.