original file : now i need to control third columns with 6 decimal space after i tried awk {‘print $1,$2; printf “%.6ft”,$3’} but the output is not what I want result : that’s weird , how can I do that will just modify third columns Answer Your print() is adding a newline charact…
Tag: bash
Why does shell command “{ command1; command2: } &” open a subshell?
As we all know, placing a list of commands between curly braces causes the list to be executed in the current shell context. No subshell is created. But when using “&” after “{}”, why two subshells are created? pid 1002 and 1003. when using “./a.out &”, only a subsh…
Extracting lines by pattern matching from multiple files and writing them to another file in linux
I have 20 files. I want to extract lines by matching pattern ‘<script src=”{%.*%}>’ from those 20 files and write those lines to new file. I also want to delete those lines from the original files. Is there a better way to do it other than what I have tried which is terrible? This is m…
awk in non-interactive is leaving some data missing
I’m running an awk command in a shell script, and it’s breaking the datafile. All of the data doesn’t load, and there’s a newline character at the end of each line. If I run this as a command, it works perfectly. I’ve just found that i can use fflush() and it seems to have solved…
How to gather IP and User Agent info and uniq them base IP address from nginx access log with AWK?
i have a sample log file I want to collect all the ip and user agent info to a file, and uniq the same IP address, how can i do with awk ? output like: Answer With sed, sort and uniq :
Cronjob script isn’t working as expected
I have a script that work perfectly fine when I manually run it by myself, but does not seem to run properly from crontab. The main error is that the (external) environment variables are not being set. I added SHELL=/bin/bash above the cronjob definition but still got the same errors. The script I have copied…
Print text in between a string pattern and a new line in bash
I have a text file that looks like this: and I’m trying to print the part between 29.04.16_09.35 (included) and the first empty line. I thought sed would work and tried using this code: but it prints everything from 29.04.16_09.35 to the end of the file. I also tried by using a single n but it still pri…
bash date, create a new object on a specific timestamp that is n hours later from now
I am struggling to understand how to set a variable to be a particular timestamp. given dt which is the current date, say 2016-05-11 17:10:00, i want to create another date variable that is (roughly) 9 hours after dt, and on the exact hour, i.e., 2016-05-12 02:00:00. In other words, I would set the new date t…
link files within directory, with simple command similar to cp
Where my question originated: When running cp source/files.all destination/, all the files within source will now also exist in destination Question: What if I didn’t want to duplicate the data from source into destination, but simply link them (with absolute path). Usually, I would run something like: …
Specify source line from csv when calling up/creating an array
I have a csv with data such as: I’ve written some code to turn each field into a variable, and also to create an array out of each word in field 2 (f2): My problem is now, because the file contains multiple lines I need some way of naming each array according to the line of data it was created