awk

sum value of a 3rd row and divide rows accordingly

☆樱花仙子☆ 提交于 2020-06-27 16:22:28
问题 I have a file as below with n number of rows, I want to total it's sum(based on 3rd column) and distribute rows accordingly in 3 different files(based on sum of each) For example- if we sum all the 3rd column values it's total is coming as 516 and if we divide it by 3 it is 172. So i want to add a rows to a file so it doesn't exceed 172 mark, same with the 2nd file and rest all rows should move to the third file. Input file a aa 10 b ab 15 c ac 17 a dy 30 y ae 12 a dl 34 a fk 45 l ah 56 o aj

how can I preserve an embedded TAB character

匆匆过客 提交于 2020-06-26 08:04:15
问题 EDIT 2019-Oct-11 - Simple example removed previous example I want awk to resepect a TAB character embedded in $0 as a content when it reprocesses the $0 input record after a field value change ( $1 , $2 , ..). Here a short example. In the output below, " t @ 48 " for example, means there is a TAB at position 48 in the $0 data record. Please note that " \t " is expanded to: TAB chr(9) as initial processing of the input (labeled raw ). Example output : $ ./tmp.awk tmp.input raw $0: ' line with

How to find a file and delete containing some string in the body using awk command from multiple files?

萝らか妹 提交于 2020-06-22 04:39:30
问题 I have multiple files in the file directory Record : Record 1.txt 2.txt 3.txt The file 2.txt contains a string abcd in the second column of the first line. How can I print all the contents in 2.txt ? How can I delete the file 2.txt? I used awk to print all the contents in that file but it only prints that line. I used find command to store the file name in the file.txt folder but it gives me an error. rm -rf Record mkdir Record cd Record echo f1 touch 1.txt echo author: efg > 1.txt echo title

how to find a file name that contains a string “abcd ” in the file content from multiple files in the directory using awk

孤人 提交于 2020-06-17 09:55:47
问题 the "bookrecords" directory has multiple files bookrecords 1.txt 2.txt 3.txt ..... file 2.txt has the content 2.txt author: abcd title: efg year: 1980 how can I get the file name 2.txt by using author: as a keyword using awk command I try to use grep command but I want to use awk command SearchRecord() { name = abcd total=`cat $bookrecords | grep -cwi $name` record=`cat $bookrecords | grep -wi $name` menu } 回答1: with awk $ awk -v search_string="$name" '$0~search_string{print FILENAME; exit}'

GDB: Set variable using pipe and awk

十年热恋 提交于 2020-06-16 17:27:15
问题 I would like to store the executable name of the current inferior in a variable. I way to obtain the executable name in the gdb CLI is the following: pipe info inferiors | awk '{ if ($1 == "*") { print $4} }' But I am unable to store the output of this expression in a variable. The expression uses single and double quotes, which makes gdb complain if it is combined with set and eval . (gdb) set $exec="pipe info inferiors | awk '{ if ($1 == "*") { print $4} }'" Argument to arithmetic operation

awk, if else conditional when record contains a value

依然范特西╮ 提交于 2020-06-16 17:27:11
问题 I'm having trouble getting an awk if/else conditional to properly trigger when the record contains a value. Running this in zsh on Mac OS Catalina. This script (issue is on second to last line)... echo "abcdefgh" > ./temp echo "abc\"\(\"h" >> ./temp echo "abcdefgh" >> ./temp echo "abcde\(h" >> ./temp val='"\("' key="NEW_NEW" file="./temp" echo $val echo $key echo $file echo "" echo "###############" echo "" awk ' BEGIN { old=ARGV[1]; new=ARGV[2]; ARGV[1]=ARGV[2]=""; len=length(old) } ($0 ~

GDB: Set variable using pipe and awk

痴心易碎 提交于 2020-06-16 17:26:49
问题 I would like to store the executable name of the current inferior in a variable. I way to obtain the executable name in the gdb CLI is the following: pipe info inferiors | awk '{ if ($1 == "*") { print $4} }' But I am unable to store the output of this expression in a variable. The expression uses single and double quotes, which makes gdb complain if it is combined with set and eval . (gdb) set $exec="pipe info inferiors | awk '{ if ($1 == "*") { print $4} }'" Argument to arithmetic operation

GDB: Set variable using pipe and awk

前提是你 提交于 2020-06-16 17:26:29
问题 I would like to store the executable name of the current inferior in a variable. I way to obtain the executable name in the gdb CLI is the following: pipe info inferiors | awk '{ if ($1 == "*") { print $4} }' But I am unable to store the output of this expression in a variable. The expression uses single and double quotes, which makes gdb complain if it is combined with set and eval . (gdb) set $exec="pipe info inferiors | awk '{ if ($1 == "*") { print $4} }'" Argument to arithmetic operation

awk, if else conditional when record contains a value

狂风中的少年 提交于 2020-06-16 17:25:28
问题 I'm having trouble getting an awk if/else conditional to properly trigger when the record contains a value. Running this in zsh on Mac OS Catalina. This script (issue is on second to last line)... echo "abcdefgh" > ./temp echo "abc\"\(\"h" >> ./temp echo "abcdefgh" >> ./temp echo "abcde\(h" >> ./temp val='"\("' key="NEW_NEW" file="./temp" echo $val echo $key echo $file echo "" echo "###############" echo "" awk ' BEGIN { old=ARGV[1]; new=ARGV[2]; ARGV[1]=ARGV[2]=""; len=length(old) } ($0 ~

zsh sed expanding a variable with special characters and keeping them

蓝咒 提交于 2020-06-16 17:24:09
问题 I'm trying to store a string in a variable, then expand that variable in a sed command. Several of the values I'm going to put in the variable before calling the command will have parentheses (with and without slashes before the left parentheses, but never before the right), new lines and other special characters. Also, the string will have double quotes around it in the file that's being searched, and I'd like to use those to limit only to the string I'm querying. The command needs to be