[Solved] how to extract word from ps -aux

Since it’s not clear what you’re trying to do: If you expect the following output: yypasswd then do ps -ef | grep yypasswd | awk ‘{print $8}’ if you want the following output: testacc 25124194 2512312620 0 08:00:53 pts/0 0:00 then do ps -ef | grep yypasswd | awk ‘{print $1, $2, $3, $4, $5, … Read more

[Solved] Complex command in exec.Command()

You don’t have to use the shell for redirection, you can just let Go do it: package main import ( “os” “os/exec” ) func main() { f, e := os.Create(“requirements.txt”) if e != nil { panic(e) } defer f.Close() c := exec.Command( “docker”, “exec”, “-it”, “demoContainer”, “bash”, “-c”, “pip freeze”, ) c.Stdout = f c.Run() … Read more

[Solved] Extract part of log file

To get everything between two pattern you can use this sed command: sed -n ‘/.* id:.*/,/.* uid:.*/p’ log.txt And you’ll get — Request — some content …. — Response — …. where -n suppresses automatic printing of pattern space p prints the current pattern space 1 solved Extract part of log file

[Solved] How to randomly generate ANSI colors in Bash/Perl?

In bash, you need to use color escape sequences with echo -e random_colors.sh #!/bin/bash TXT=’the quick brown fox jumped over the lazy dog.’ WORDS=( $TXT ) for WORD in “${WORDS[@]}”; do let “i=$RANDOM % 256” echo -en “\e[38;5;${i}m$WORD \e[0m”; done; echo Running this 10 times: for i in `seq 1 10`; do bash random_colors.sh; done … Read more

[Solved] Conversion of large .csv file to .prn (around 3.5 GB) in Ubuntu using bash

It’s not clear from your question as you didn’t provide sample input/output we could test against but it SOUNDS like all you’re trying to do is this: $ cat tst.awk BEGIN { split(“7 10 15 12 4″,w) FPAT=”[^,]*|\”[^\”]*\”” } { gsub(/””/,RS) for (i=1;i<=NF;i++) { gsub(/”/,””,$i) gsub(RS,”\””,$i) printf “<%-*s>”, w[i], substr($i,1,w[i]) } print “” } $ … Read more

[Solved] Arithmetic operations using numbers from grep

Assumptions: we want to match on lines that start with the string number we will always find 2 matches for ^number from the input file not interested in storing values in an array Sample data: $ cat file.dat number1: 123 not a number: abc number: 456 We’ll use awk to find the desired values and … Read more

[Solved] Pass variable as options to curl in shell script linux [duplicate]

You need to use an array, not a regular variable. curl_std_opts=( -k –header ‘Content-Type: application/json’ –header ‘Accept: application/json’) curl “${curl_std_opts[@]}” -X POST –data “{\”actual\”: $BAL}” “$websiteurl” For safety, you should use a tool like jq to generate your JSON rather than relying on parameter interpolation to generate valid JSON. curl “${curl_std_opts[@]}” -X POST –data “(jq … Read more

[Solved] Bash: Remove all occurring pattern except 1

With no sample input, I will just guess and maybe it will help: cat file header for file 1111 header for file 1111 2222 header for file 3333 4444 5555 awk ‘/header/&&c++>0 {next} 1’ file header for file 1111 1111 2222 3333 4444 5555 Though I am not the greatest in sed sed ‘1!{/^header/d;}’ file … Read more