I’m having a hard time finding the correct way to do any advanced file-system operations on Linux using Scala. The one which I really can’t figure out if best described by the following pseudo-code: Basically open a file in append mode (create it if it’s non existent), get an exclusive lock to it and write to it (with the implicit
Tag: file
Editing single value in file in C efficiently
I have a C program that currently edits a single value in a parameter file by using sed through a system call. I’d like to change the program to use the C file libraries to edit this value, but the only way I know how to do this is by reading in the entire file, changing the value, and rewriting
How to replace lines that contains integers by using sed
I have a file that contains two fields. The first field may or may not contain an Integer. If it contains an integer and a dot follows the integer I would like to manipulate part of second field. So As an example: I couldn’t make it since I have very limited knowledge in regex. I would be very appreciate if
Why Sed cannot replace lines that contains . + and *
I have a large file and some of the lines are as follows: I want to replace ….+UNKNOWN part with the …+PUNCT To do that, I did the following: However, none of the lines gone. I couldn’t find my error, could you help me about ? Answer In some versions of sed, + has a special meaning, use + to
Overwriting TS Stream File with FFMPEG in Linux
I’m trying to convert rtmp streams to m3u8 stream. To reach that aim I use FFMPEG. Now, there is no problem with converting and downloading. However, it writes lots of .ts file such as channel0000.ts,channel0001.ts,channel0002.ts. Per every 10 seconds, 1 ts file is created. In this point, I want a single ts file. In other words, I need overwriting because
Put quotes around string before first forward slash in line by line file read
I am writing a bash script that deletes all the files whose paths are given in delete.txt. delete.txt is thousands of lines long, each line has a path that is structured like this: Where there is a space in the name of the first directory. Currently, my bash script reads each line of delete.txt, saves it to$line and deletes it.
Copy numbered image files where number is less than X
I have a folder of 10,000 JPEg’s labeled 1.JPG to 10000.JPG. I want to copy all files that have a number less than (or greater than) X to another directory. What’s the best way to do this from the command line? Answer A simple brace expression would zap this, here I am guessing at your number range of course: More
How to edit a big file
Imagine a huge file that should be edited by my program. In order to increase read time I use mmap() and then only read out the parts I’m viewing. However if I want to add a line in the middle of the file, what’s the best approach for that? Is the only way to add a line and then move
In linux system, how to find the words (immediately next alone) next to a given word in a file?
I need to find all the table names alone in all select statements in my query log. Is there any way to grep (or) any other option, to take the strings that comes immediately after the word FROM in my file .. Example: file contains something like this Now I want the list of the distinct tables alone from the
Linux file descriptor – getting current redirection stdout file?
I’m trying to get the current stdout redirection, and having some trouble. I have a script that is always run with stdout redirection ie: In myscript.sh, I need to find out what file it is being output to. I’m trying this currently (not working): That’s outputting logfile = /tmp/sflq.r3f, for instance. I need to instead find that it’s going to