[Solved] Unix Command | ps [closed]

Copied from man ps: -u userlist Select by effective user ID (EUID) or name. This selects the processes whose effective user name or ID is in userlist. The effective user ID describes the user whose file access permissions are used by the process (see geteuid(2)). Identical to U and –user. Meaning: it prints all the … Read more

[Solved] How to create a flag with getopts to run a command

Your script has a number of problems. Here is the minimal list of fixes to get it working: While is not a bash control statement, it’s while. Case is important. Whitespace is important: if [“$CHECKMOUNT”= “true”] doesn’t work and should cause error messages. You need spaces around the brackets and around the =, like so: … 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] power shell script to get drive space ( percentage used and free ) [duplicate]

You can try this: Get-WmiObject -Class win32_Logicaldisk -ComputerName localhost | where {($_.DriveType -eq 3 -or $_.DriveType -eq 2) -and $_.FileSystem -ne $null } | Select -Property @{Name=”Volume”;Expression = {$_.DeviceID -replace “:”,””}}, @{Name=”Free”;Expression = { “{0:N0}%” -f (($_.FreeSpace/$_.Size) * 100) } } solved power shell script to get drive space ( percentage used and free ) … Read more

[Solved] How to process this text [closed]

You could simply do this through awk, $ awk -F[,-] ‘{var=$1″-“$2; for (i=3;i<=NF;i++){print var”-“$i}}’ file 86-22-63385835 86-22-63385836 86-22-63385933 86-0577-88609993 86-0577-88835386 86-21-58947602 86-21-58947603 0086-755-33186858 0086-755-33186862 0086-755-33186859 2 solved How to process this text [closed]

[Solved] Problem replacing numbers with words from a file

this can be accomplished in a single awk call. associate numbers with champions in an array and use it for replacing numbers in second file. awk ‘BEGIN{FS=OFS=”,”} NR==FNR{a[$1]=$2;next} {$1=a[$1];$2=a[$2]} 1’ champions.csv top.csv Olaf,Annie,3 Galio,Annie,5 Twisted Fate,Annie,6 Xin Zhao,Annie,1 Urgot,Annie,10 LeBlanc,Annie,9 Vladimir,Annie,11 Kayle,Twisted Fate,12 LeBlanc,Xin Zhao,2 Galio,Galio,6 in case there should be some numbers in top.csv … Read more

[Solved] grep values and re-arranging the file

Try this awk: awk -F'”‘ ‘NR%2{p1=$4;next} {print p1 “https://stackoverflow.com/” $4}’ Test: $ awk -F'”‘ ‘NR%2{p1=$4;next} {print p1 “https://stackoverflow.com/” $4}’ file abc/123abc bac/bac123 cde/cd123 b4u/b4u234 2 solved grep values and re-arranging the file

[Solved] How can I execute an MySQL command through a shell script using if -else for condition based?

Mysql won’t understand if ..else shell syntax and so you will need to execute mysql within each if, else block with -e for execution e.g: … elseif [ “$(date +%m)” -eq 2 ] then mysql –login-path=local -e “use testdb;select COUNT(id) from xxx where app_id =’ABC’ and date(creation_date) between ‘$(date +%F -d “tomorrow -28 days”)’ and … 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