My file Threadout.txt contains like Thread 1/1/25/100 val1=$(grep 'Thread' Threadout.txt | awk -F&quot;/&quot; '{print $1}')   val2=$(grep 'Thread' Threadout.txt | awk -F&quot;/&quot; '{print $2}')     val3=$(grep 'Thread' Threadout.txt | awk -F&quot;/&quot; '{print $3}')   val4=$(grep 'Thread' Threadout.txt | awk -F&quot;/&quot; '{print $4}')  for((i=1;i&lt;5;i++))   do     val[i]=$(grep 'Thread' Threadout.txt | awk -F&quot;/&quot; '{print $[i]}')     echo $val[i]  done  I have tried this array but not giving the correct result like 1 1 25 100 values. Any error?
123774
How to write the below lines using array?? val1=$(grep 'Thread' Threadout.txt | awk -F&quot;/&quot; '{print $1}')    val2=$(grep 'Thread' Threadout.txt | awk -F&quot;/&quot; '{print $2}')  val3=$(grep 'Thread' Threadout.txt | awk -F&quot;/&quot; '{print $3}')  val4=$(grep 'Thread' Threadout.txt | awk -F&quot;/&quot; '{print $4}')  Threadout.txt contains like &quot;Thread 1/1/25/100&quot;
76754
the function awk '!seen[$0]++' print the new occurrences in an input pipe.  I am however unable to add a pipe after. E.g  my_function_with_ouput | awk '!seen[$0]++' | while read j do echo $j done   Doesn't produce any output.
38993
I am new to UNIX and am trying to learn basic level text processing in UNIX so maybe this question may seem very basic but I would really appreciate any guidance.  I have a text file as below  A 1 B 2 C 9 D 1 A 5 B 3 C 4 A 6 C 7 A 5 C 1   for which I was able to piece together a command with some help as below  cat | awk 'BEGIN{OFS=FS=" "}!(($1,$2)in c){c[$1,$2]=1;r[$1]=r[$1] OFS $2} END{for(i in r){print i r[i]}}'   inside a shell script to get it to the format below:  A 1 5 6 5 B 2 3 C 9 4 7 1 D 1   My shell script will also take an argument k  (=7 say)  In this case, my script should sample 1 element from each box (A,B,C,D) until it has a total of 7 elements sampled. This will be like follows: First pick 1 from A, then 2 from B, 9 from C, 1 from D, 5 from A, 3 from B, 4 from C and display  A 1 5 B 2 3 C 9 4 D 1   If instead I had k = 9 as my input, then my output should be  A 1 5 6 B 2 3 C 9 4 7 D 1
94270
The command that I have prints out two of the lines whenever FW_6.0.0 is found, below is the code:  grep -oP 'FW_6.0.0, (.*)$' file   Below is the output, both has the same value of FW_6.0.0  FW_6.0.0, SUCCESS FW_6.0.0, OK   I would like to match two words, that is FW_6.0.0 and SUCCESS that can be found on the same line so that it prints this out:  FW_6.0.0, SUCCESS and eliminates FW_6.0.0, OK
95955
I have a file that I would like to break up into multiple files with uniq values for the first column. For example, here is a file:  fileA.txt   1    Cat 1    Dog 1    Frog 2    Boy 2    Girl 3    Tree 3    Leaf 3    Branch 3    Trunk   I would like my output to look something like this:  file1.txt   1    Cat 2    Boy 3    Tree   file2.txt  1    Dog 2    Girl 3    Leaf   file3.txt  1    Frog 3    Branch   file4.txt  3    Trunk   If a value does not exist, I want it to be skipped. I have tried to search for similar situations to mine, but I've come up short. Does anyone have idea of how to do this?  Edit: My awk version is: awk version 20070501
81486
I have a client that updates/writes into myfile.csv arbitrarily.  I've written the following code, I left the MySQL snippet out:  while true do   awk_variables_value_array=`tail -n2 myfile.csv | awk -F, '$7 == "status" {print $4, $5, $10 }'`   var1=${awk_variables_value_array[0]}   var2=${awk_variables_value_array[1]}   var3=${awk_variables_value_array[2]}    if[ "var3" -gt "0" ]   --MYSQL SNIPPET IS--   fi done  Q: tail -n2 reads the last 2 lines, how can I change it is so it's the second last line  the file:  where n is the last line of the file  line 1 line 2 line 3 line 4 .... line n-2 line n-1 line n  current output yields:  line n-1 line n   I would like it so that the output is:  line n-1
92320
I am trying to print the lines using the repetition symbol {n} but it is not working.  For. e.g. I want to print all lines whose length is 4 char long   awk '/^.{4}$/' test_data   The above code is not printing that .How to fix it so that I can use the repetition symbol? I know the alternative like awk  '/^....$/' test_data and awk  'length ==3 ' test_data
23359
I'll appreciate your help with the following issue:  I'm trying to set an array which contains a variable as part of the array name, example: Arr_$COUNTER (where $COUNTER is changed based on a loop count)  Every possible way I have tried came up with an error, such as "bad substitution" or "syntax error near unexpected token"  Here is the entire flow:   There is one file which contain multiple lines. each line has 6 values separated by space  10 20 30 40 50 60   100 200 300 400 500 600  The script, is meant to read each line from the file, and declare it as an array (with the line number which is the variable. as a test, each value should be printed and eventually another function will be executed on each value.  #!/bin/bash COUNTER=1 LINES=`wc -l VALUES_FILE.txt | awk '{print $1}'` echo "Total number of lines "$LINES echo while [ $COUNTER -le $LINES ] do echo "Counter value is $COUNTER" field=`awk "NR == $COUNTER" VALUES_FILE.txt` echo "Field = $field" declare -a "arr$COUNTER=($field)" echo "arr$COUNTER[0] = ${arr$COUNTER[0]}" echo "arr$COUNTER[1] = ${arr$COUNTER[1]}" echo "arr$COUNTER[2] = ${arr$COUNTER[2]}" echo "arr$COUNTER[3] = ${arr$COUNTER[3]}" echo "arr$COUNTER[4] = ${arr$COUNTER[4]}" echo "arr$COUNTER[5] = ${arr$COUNTER[5]}" let COUNTER=COUNTER+1 echo done echo "The End" echo    Here is the result:   Total number of lines 2  Counter value is 1 Field = 10 20 30 40 50 60 ./sort.sh: line 12: arr$COUNTER[0] = ${arr$COUNTER[0]}: bad substitution The End    What should be changed / fixed in order to have it working properly?  thank !
61729
How can I write this with an AIX script correctly?  My requirement is to write this command in test.txt:  clock=$(prtconf -s | awk '{print $4,$5}')   I tried this command:  print 'clock=$(prtconf -s | awk '{print $4,$5}')' &gt; test.txt   Output written in test.txt gives me:  clock=$(prtconf -s | awk {print ,})   If I use " " quotes:  print "clock=$(prtconf -s | awk '{print $4,$5}')"   It gives me directly to:  clock=3612 MHz   How can I solve this?
27936
I've a command that outputs data to stdout (command1 -p=aaa -v=bbb -i=4). The output line can have the following value:  rate (10%) - name: value - 10Kbps   I want to grep that output in order to store that 'rate' (I guess pipe will be useful here). And finally, I would like that rate to be a value of a parameter on a second command (let's say command2 -t=${rate})  It looks to be tricky on my side; I would like to know better how to use pipes, grep, sed and so on.  I've tried lots of combinations like that one but I'm getting confused of these:  $ command1 -p=aaa -v=bbb -i=4 | grep "rate" 2&gt;&amp;1 command2 -t="rate was "${rate}
95611
I have a server access log, with timestamps of each http request, I'd like to obtain a count of the number of requests at each second. Using sed, and cut -c, so far I've managed to cut the file down to just the timestamps, such as:     22-Sep-2008 20:00:21 +0000   22-Sep-2008 20:00:22 +0000   22-Sep-2008 20:00:22 +0000   22-Sep-2008 20:00:22 +0000   22-Sep-2008 20:00:24 +0000   22-Sep-2008 20:00:24 +0000   What I'd love to get is the number of times each unique timestamp appears in the file. For example, with the above example, I'd like to get output that looks like:     22-Sep-2008 20:00:21 +0000: 1   22-Sep-2008 20:00:22 +0000: 3   22-Sep-2008 20:00:24 +0000: 2   I've used sort -u to filter the list of timestamps down to a list of unique tokens, hoping that I could use grep like  grep -c -f &lt;file containing patterns&gt; &lt;file&gt;   but this just produces a single line of a grand total of matching lines.  I know this can be done in a single line, stringing a few utilities together ... but I can't think of which. Anyone know?
13068
Given a file like this:  1,768,12,46576457,7898 1,123,435,134,146 2,345,6756856,12312,1311 5,234,567465,12341,1341 1,3245,4356345,2442,13 9,423,2342,121,463 9,989,342,121,1212   I would like to list all rows (in bash terminal) such that the value in column 1 appears at least twice (in column 1). The result should be  1,768,12,46576457,7898 1,123,435,134,146 1,3245,4356345,2442,13 9,423,2342,121,463 9,989,342,121,1212
65652
In bash, I know that it is possible to write a for loop in which some loop control variable i iterates over specified integers.  For example, I can write a bash shell script that prints the integers between 1 and 10: #!/bin/bash  for i in {1..10} do  echo $i done  Is it possible to instead iterate over a loop control variable that is a string, if I provide a list of strings?  For example, suppose that I have a string fname that represents a file name.  I want to call a set of commands for each file name.  For example, I might want to print the contents of fname using a command like this: #!/bin/bash  for fname in {&quot;a.txt&quot;, &quot;b.txt&quot;, &quot;c.txt&quot;} do  echo $fname done  In other words, on the first iteration, fname should have the value fname=&quot;a.txt&quot;, while on the second iteration, fname should have the value fname=&quot;b.txt&quot;, and so on.  Unfortunately, it seems that the above syntax is not quite correct.  I would like to obtain the output:  a.txt b.txt c.txt  but when I try the above code, I obtain this output:  {a.txt, b.txt, c.txt}  Can you please help me determine the correct syntax, so that I can iteratively change the value/contents of the variable fname?  Thank you for your time.
32551
My input file is,  ami21 ami65 ami67 ami66 ami88 ami76 ami29 ami55  ami54 ami32   Using a single command line I need the output as,  ami22 ami66 ami68 ami67 ami89 ami77 ami30 ami56 ami55 ami33   I used the command  awk -vRS=ami '{$0=$0+1;ORS=RT}++n' inputfile &gt; outputfile   but I got the outputfile as ami21ami65ami67ami66ami88ami76ami29ami55ami54ami32  i.e. all strings are written in same line and without space. Could anyone suggext me some better command line.
113295
I am trying the contents of an array into a file with each element of the array in a new line in the file.  IFS=$'\n'    echo "${mtches[@]}" &gt; sample1.txt     The content of mtches is "qwe" and " asd". But the sample1.txt file contains qwe asd in a single line. Why is it not taking IFS value into the picture?
104860
I am trying to delete two lines ( 7 and 8) from a .txt file. For this I am using following code:-  #!/bin/sh Column="7" sed '"$Column",8d' myfile.txt &gt; result.txt   on running this script, I am getting this error:-  sed: -e expression #1, char 1: unknown command: `"'   Please tell me how to use variable as a part of sed command.
40934
I have a couple of big text files and in the file UNIQS.txt I have a list of strings to grep from another file. The code I use is  grep -f UNIQS.txt EEP_VSL.uniqs.sam &gt; UNIQ_templates.sam   which does nothing - the file generated is empty. But when I do  grep -F -f UNIQS.txt EEP_VSL.uniqs.sam &gt; UNIQ_templates.sam   it works correctly. This confuses me because I didn't think grep would interpret the entries in UNIQS.txt as regexp patterns without quotes and slashes and so on being in the file (which there aren't). Is it the case in general that if you are getting the patterns from a file then it will automatically think that they are regexp patterns?  Edit: In the UNIQS.txt file, there are newline separated strings of the form  HWI-ST365:215:D0GH0ACXX:2:1101:10034:186783   (called template names) and the file EEP_VSL... tab separated columns, with about 14 columns and the first column is the template name, so basically I want to extract the line corresponding to each template in the file.