[Solved] For every possible pair of two unique words in the file, print out the count of occurrences of that pair [closed]

It seems inconceivable that the purpose of your assignment determining the frequency of word-pairs in a file would be to have you wrap a piped-string of shell utilities in a system call. What does that possibly teach you about C? That a system function exists that allows shell access? Well, it does, and you can, … Read more

[Solved] how to get the time after two minutes [closed]

To get the date-string in bash: echo “Current: ” $(date +”%Y”-“%m”-“%d”T”%H”-“%M”-“%S”) echo “+2 min : ” $(date –date=”@$(($(date +%s)+120))” +”%Y”-“%m”-“%d”T”%H”-“%M”-“%S”) prints Current: 2014-09-10T15-58-15 +2 min : 2014-09-10T16-00-15 Read the time from string and print +2min string str=”2014-09-10T15-58-15″ new=$(date –date=”@$(($( IFS=”-T” read y m d H M S <<< “$str”;date –date=”$y-$m-${d}T$H:$M:$S” +%s )+120))” +”%Y”-“%m”-“%d”T”%H”-“%M”-“%S”) echo “From … Read more

[Solved] How do I retrieve the processor time in Linux without function calls?

You should read time(7). Be aware that even written in assembler, your program will be rescheduled at arbitrary moments (perhaps a context switch every millisecond; look also into /proc/interrupts and see proc(5)). Then any hardware timer is meaningless. Even using the RDTSC x86-64 machine instruction to read the hardware timestamp counter is useless (since after … Read more

[Solved] How to extract specific columns in log file to csv file

You would probably need to use a regular expression to find lines that contain the values you want and to extract them. These lines can then be written in CSV format using Python’s CSV library as follows: import re import csv with open(‘log.txt’) as f_input, open(‘output.csv’, ‘w’, newline=””) as f_output: csv_output = csv.writer(f_output) csv_output.writerow([‘Iteration’, ‘loss’]) … Read more

[Solved] Extract data from txt file and create new file based on specific text dynamically

Here is an easy-to-read solution with Bash and grep: #!/bin/bash while read line ; do if FILE=$(grep -P -o ‘[a-z]*\.txt(?= – Starting)’ <<< “$line”); then F=”$FILE” fi if ! grep ‘\*\*\*\*’ <<< “$line” ; then echo “$line” >> “$F” fi done It gives the following result $ cat file.txt ****************** abc.txt – Starting point ******************** … Read more

[Solved] Extracting the values within the square braces

In GNU awk: $ awk -F”[][]” ‘{split($2,a,”-“); for(i=a[1];i<=a[2];i++) print $1 i $3}’ file app-server-l112.test.com app-server-l113.test.com app-server-l114.test.com app-server-l115.test.com server-l345.test.com server-l346.test.com server-l347.test.com server-l348.test.com dd-server-l2.test.com dd-server-l3.test.com dd-server-l4.test.com split to fields by [ and ] using FS use split the get the range start (a[1]) and end (a[2]) iterate the range with for and output There is no checking … Read more

[Solved] What are the essential things that a new ubuntu server should have installed, for development purposes? [closed]

For any sort of web development, I would recommend apache2. For databases, I would recommend mysql-server or postgresql. For Java (as well as C++ and some others), a popular option is eclipse, although netbeans is also good. If you want to see what’s going on under the hood, wireshark is a great network monitoring utility … Read more

[Solved] How are signals handled in Unix?

The operating system stops running the thread receiving the signal and runs the signal handler. When it returns the original thread restarts where it was. If the signal handler is already running when another signal comes in, the action is configurable in the sigaction call. solved How are signals handled in Unix?