Answer by ozzy for Replace lines in multiple files matching a pattern with...
With GNU awk (i.e. gawk) you could do: gawk -i inplace '/mock/ { getline < "mock.txt" } 1' test{1..3}.txt Like sed, gawk offers inplace editing. The above command looks for the regex-pattern mock,...
View ArticleAnswer by ozzy for How to sort a file with multiple delimiters?
You could use this: awk 'NR<=4 {print $0; next } { print $0 | "sort -k6,6 -t\\|" }' listing.txt It runs awk on listing.txt; instead you could pipe the data into awk (leaving out the listing.txt at...
View ArticleAnswer by ozzy for command line tool to download complete podcast from rss feed
I'm not really familiar with rss feeds or the format that they come in. Neither do I see, using newsbeuter for instance, the close to 200 episodes that you say are present in the feed (I see only 10...
View ArticleAnswer by ozzy for Find and copy with exec not working
Your command appears to have two issues, the first of which may not matter much in your case, but is nevertheless worth pointing out: (i) it is not generic in the sense that it will not be able to...
View ArticleAnswer by ozzy for How to make symlink executable?
Bash will find an executable specified by its bare filename (i.e. without preceding path elements) only if it is on its search path, which is stored in the PATH variable. The current directory is not...
View ArticleAnswer by ozzy for Can't run parallel zgrep with regex
If you are using the parallel command from the moreutils package, your command could be simplified like this: parallel zgrep -e "\(text1\|text2\).*Exception" -- my.log*.gz This will run parallel...
View ArticleAnswer by ozzy for How to grep a line who has execution time greater than X
Assuming that the lines continue after "Lambda", as suggested by the OP, this command should work: gawk 'match($0, /execution\stime:([0-9]+)s/, a) && a[1] > 10 { print $0 }' logfile with...
View ArticleAnswer by ozzy for wget image problem for daily wallpaper script
Your script needs a bit of a makeover. The two lines following the #Set image url, name and location line are broken for various reasons (e.g. incorrect grep syntax, incorrect assignment). In addition,...
View ArticleAnswer by ozzy for Usage of nc with timeouts in ms
I don't think it is possible with nc alone. But you can additionally use the timeout tool (GNU coreutils package) which allows you to run a command with a timelimit specified as a floating point...
View ArticleAnswer by ozzy for Exit shell script containing indefinitely running java...
The question is a bit puzzling to me, not in the least because of the pipe (to tee) that you apparently wish to use. To maintain this functionality, you could use the following script: #!/bin/ksh tee...
View ArticleAnswer by ozzy for Write shell script to analysis log file
In an unpolished version, a Bash-script could look like this, assuming that your data is contained in datafile: #!/bin/bash printf "IPs where status is fail:\n" grep -z -oP 'IP=\K.*\n(?=STATUS=FAIL)'...
View ArticleAnswer by ozzy for Getting the last sentence of a running program from...
This should work: grep -m1 -oP '(\d{1,3}\.?){4}:\d{1,5}' <( your-qemu-command 2>&1 ) <( your-qemu-command 2>&1 ) is a process substitution that launches qemu with stdout/stderr...
View ArticleAnswer by ozzy for About ||||| (pipe or vertical bars) In yad --form --button
I cannot reproduce the situation you describe entirely, but I think you need to ask yourself what you want yad to do when a button is pressed, or, more specifically, how yad should communicate any user...
View ArticleAnswer by ozzy for Understanding why hostname -i returns strange IP address
Unlike the hostname -I command, which just lists all configured IP addresses on all network interfaces, the hostname -i command performs name resolution (see the hostname man page). Since your newly...
View ArticleAnswer by ozzy for Run parallel command and redirect the output to files with...
Well, this is a somewhat over-engineered Bash-solution, but it works and hopefully clarifies the use of the parallel command: function xx(){ curl "https://jsonplaceholder.typicode.com/todos/$1" >...
View ArticleAnswer by ozzy for how can I merge two text files together
If file1 is your first text file, and file2 is your second text file, this should work in Bash: join -a 1 <(sort -k1,1 file2) <(sed -E -e 's/([^\s])\(/\1 (/' file1 | sort -k1,1) Join is called...
View ArticleAnswer by ozzy for Awk - convert time value to decimal value
How about this? awk -F: '{printf "%.1f", ($1*60+$2)/60}' <<< 1:30
View ArticleAnswer by ozzy for how to find & replace a file path listed in a file
You could use: sed -i -E -e 's/(\/.*\/)(.*\.idt)/\2/' file_list This performs an in-place (-i) replacement of all /..../filename.idt filepaths with filename.idt ("all" as in: the first occurrence on...
View ArticleAnswer by ozzy for want to Rename Images In Bulk in Linux
In Bash, the solution could look like this: #!/bin/bash shopt -s extglob for fn_old in *.jpg; do i=0 fn_new=${fn_old##+([-0-9])} # strip leading number sequence in basename...
View ArticleAnswer by ozzy for How to extract duplicate numbers from a log file?
You could use: grep -oP 'SubscriberNumber=\K(\d+)' logfile | sort -n | uniq -cd grep -oP 'SubscriberNumber=\K(\d+)' logfile isolates all individual SubscriberNumbers from your logfile; sort -n sorts...
View Article