Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have 1 file where data gets added every 10 min, I want to get updated data which can be stored in new file(inc1.txt) through script.
My path for file as /home/asda/Desktop/inc.txt
How this can be achive?
Use tac to cat the file backwards, and quit when you get to your marker:
tac /home/asda/Desktop/inc.txt | sed /Marker/q | tac
then add a new Marker at the end to remember where you last finished
echo "Marker" >> /home/asda/Desktop/inc.txt
This has the disadvantage that it alters your file, but you can grep out the markers when you use the file like this:
grep -v Marker /home/asda/Desktop/inc.txt
Of course, you should make the marker something that doesn't naturally occur in your file.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 10 months ago.
The community reviewed whether to reopen this question 10 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I have a bash file that is pretty long, and I don't want to spend hours painstakingly going through and making it a one liner. Is there some online tool or command I can use to make my file into a one liner?
I already tried looking for beautifiers and formatters, but none do what I need it to, and I even searched on here for about an hour and all I could find was stuff about how to make a one liner not how to convert my entire file into a one liner.
This is a horrible idea. Do not do it.
That said, if you define the following function:
onelineify() {
script_content=$(gzip -9 <"$1" | base64 -w0)
printf '%s\n' '#!/usr/bin/env bash'
printf 'eval "$(base64 -d <<<%q | gunzip -c)"\n' "$script_content"
}
onelineify yourscript will write a version of your script that is only one line (beyond the shebang) to stdout.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
To switch two filenames in place I can:
mv first firstTmp
mv second first
mv firstTmp second
Is this possible with simple one-liner, and preferably without using temporal filename?
You just think, how will it be possible without using a temporary file. If you change the name of the file to second file you are going to lose the second file forever. You can do it without a temp file but still the process is more time consuming. You have to rename and move the file to a different (say \tmp) directory and second file to the name of first file and copy the file from \tmp to your current directory.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How do I reduce the size of a file using tail?
I just need the last 1000 lines of the file. I need the trimmed file name to remain the same.
tail -1000 file.txt
To make a new file
tail -1000 file.txt > newfile.txt
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
I have a folder full of images with several different random file names to help organize this mess I would like to, in one command rename all of them to a sequential order so if I have 100 files it starts off naming the first file file-1.jpg file-2.jpg etc. Is this possible in one command?
The most concise command line to do this I can think of is
ls | cat -n | while read n f; do mv "$f" "file-$n.jpg"; done
ls lists the files in the current directory and cat -n adds line numbers. The while loop reads the resulting numbered list of files line by line, stores the line number in the variable n and the filename in the variable f and performs the rename.
I was able to solve my problem by writing a bash script
#!/bin/sh
num=1
for file in *.jpg; do
mv "$file" "$(printf "%u" $num).jpg"
let num=$num+1
done
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to change some numbers in a rule, like 192.168.1.2 to 192.168.1.x, where x is a value between 3-254. So'll have multiple lines, one with the value 192.168.1.2, other with the value 192.168.1.3, and so on.
Well, I've no clue how to do that.
If someone know of a program or some way to do using a script in linux, please let me know.
Here's one way using GNU sed. Simply replace X with the value you wish to use.
sed 's/\(\([0-9]\{1,3\}\.\)\{3\}\)[0-9]\{1,3\}/\1X/g' file.txt
Test:
echo "192.168.1.4" | sed 's/\(\([0-9]\{1,3\}\.\)\{3\}\)[0-9]\{1,3\}/\1X/g'
Result:
192.168.1.X
Another option, using awk to avoid the hairy regex route (nothing wrong with regexes in general, but sometimes they can make your eyes bleed...):
awk -F. '{printf "%s.%s.%s.x\n",$1,$2,$3}'