Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 在编辑的需求中列出的输出要求中,您可以使用重定向回awk的循环: awk '/^FILE -/ { fil=$3; # When the output start with "FILE -" set fil to the third space delimited field next # Skip to the next line } { arr[fil][$0]="" # Set up a 2 dimensional array with the search term (fil) as the first index and the name of the file the second } END { for (i in arr) { # Loop through the array printf "%s => ",i; First print the search term in the format required for (j in arr[i]) { printf "%s,",j # Print the file name followed by a comma } printf "\n" # Print a new line } }' <<< "$(while read line # Read list.txt line by line do echo "FILE - $line"; Echo a marker for identification in awk grep -l "$line" C:\dirofcsv ; # Grep for the line done < list.txt)" >> print.txt awk'/^FILE-/{fil=$3;#当输出以“FILE”开头时,将fil设置为第三个空格分隔的字段 下一行#跳到下一行 } {arr[fil][$0]=“”#设置一个二维数组,第一个索引是搜索项(fil),第二个索引是文件名 } 结束{for(i in arr){#通过数组循环 printf“%s=>”,i;首先以所需格式打印搜索词 对于(j in arr[i]){ printf“%s”,j#打印文件名,后跟逗号 } printf“\n”#打印新行 } }'print.txt_Bash_Loops_Unix_Search_Grep - Fatal编程技术网

Bash 在编辑的需求中列出的输出要求中,您可以使用重定向回awk的循环: awk '/^FILE -/ { fil=$3; # When the output start with "FILE -" set fil to the third space delimited field next # Skip to the next line } { arr[fil][$0]="" # Set up a 2 dimensional array with the search term (fil) as the first index and the name of the file the second } END { for (i in arr) { # Loop through the array printf "%s => ",i; First print the search term in the format required for (j in arr[i]) { printf "%s,",j # Print the file name followed by a comma } printf "\n" # Print a new line } }' <<< "$(while read line # Read list.txt line by line do echo "FILE - $line"; Echo a marker for identification in awk grep -l "$line" C:\dirofcsv ; # Grep for the line done < list.txt)" >> print.txt awk'/^FILE-/{fil=$3;#当输出以“FILE”开头时,将fil设置为第三个空格分隔的字段 下一行#跳到下一行 } {arr[fil][$0]=“”#设置一个二维数组,第一个索引是搜索项(fil),第二个索引是文件名 } 结束{for(i in arr){#通过数组循环 printf“%s=>”,i;首先以所需格式打印搜索词 对于(j in arr[i]){ printf“%s”,j#打印文件名,后跟逗号 } printf“\n”#打印新行 } }'print.txt

Bash 在编辑的需求中列出的输出要求中,您可以使用重定向回awk的循环: awk '/^FILE -/ { fil=$3; # When the output start with "FILE -" set fil to the third space delimited field next # Skip to the next line } { arr[fil][$0]="" # Set up a 2 dimensional array with the search term (fil) as the first index and the name of the file the second } END { for (i in arr) { # Loop through the array printf "%s => ",i; First print the search term in the format required for (j in arr[i]) { printf "%s,",j # Print the file name followed by a comma } printf "\n" # Print a new line } }' <<< "$(while read line # Read list.txt line by line do echo "FILE - $line"; Echo a marker for identification in awk grep -l "$line" C:\dirofcsv ; # Grep for the line done < list.txt)" >> print.txt awk'/^FILE-/{fil=$3;#当输出以“FILE”开头时,将fil设置为第三个空格分隔的字段 下一行#跳到下一行 } {arr[fil][$0]=“”#设置一个二维数组,第一个索引是搜索项(fil),第二个索引是文件名 } 结束{for(i in arr){#通过数组循环 printf“%s=>”,i;首先以所需格式打印搜索词 对于(j in arr[i]){ printf“%s”,j#打印文件名,后跟逗号 } printf“\n”#打印新行 } }'print.txt,bash,loops,unix,search,grep,Bash,Loops,Unix,Search,Grep,一艘班轮: awk '/^FILE -/ { fil=$3;next } { arr[fil][$0]="" } END { for (i in arr) { printf "%s => ",i;for (j in arr[i]) { printf "%s,",j } printf "\n" } }' <<< "$(while read line;do echo "FILE

一艘班轮:

awk '/^FILE -/ { fil=$3;next } { arr[fil][$0]="" } END { for (i in arr) { printf "%s => ",i;for (j in arr[i]) { printf "%s,",j } printf "\n" } }' <<< "$(while read line;do echo "FILE - $line";grep -l "$line"  C:\dirofcsv done < list.txt)" >> print.txt
awk'/^FILE-/{fil=$3;next}{arr[fil][$0]=''}END{for(i in arr){printf“%s=>”,i;for(j in arr[i]){printf“%s”,j}printf“\n}”print.txt


是的,这就是我的意思,我的描述上的签名错误。但是结果是一样的,它只打印文件的最后一行。哦,好的,append
>
应该在那里。斯里坦克斯,这在我的任期内有效。但是找不到如何在结果之前编写查询词,我无法理解哪个结果对应于哪个查询。你认为我需要为此编写一个循环吗?是的,最简单的实现应该是循环,而且由于程序也在映射多对多,所以循环更可取。但是,你可以使用字典和/或JSON使用AWK试用,在你得到GRIP的输出,比如变量或者管道。是的,你应得的。你说的是解决方案中的箭头?我点击了很多次,但是一直是零,我是新来的,对选项不太了解。是的,这就是我的意思,我描述上的符号错误。但是结果是一样的,它只打印文件的最后一行。哦,好的,append
>
应该在那里。斯里坦克斯,这在我的任期内有效。但是找不到如何在结果之前编写查询词,我无法理解哪个结果对应于哪个查询。你认为我需要为此编写一个循环吗?是的,最简单的实现应该是循环,而且由于程序也在映射多对多,所以循环更可取。但是,你可以使用字典和/或JSON使用AWK试用,在你得到GRIP的输出,比如变量或者管道。是的,你应得的。你说的是解决方案中的箭头?我点击了很多次,但是一直是零,我是新来的,不太了解选项。谢谢你,这就是我要找的!可以逐行打印吗?比如:doggo=file2,file5鼠标=file4,file2。因为我有所有的指纹,但不知道谁属于哪个术语。只要从grepIt中删除l标志给我太多信息,我需要保留文件结果的请求行1,然后是文件结果的请求行2,要做到这一点,你需要阅读list.txt的每一行,然后用这一行执行grep。我为循环添加了一个额外的解决方案谢谢你,这就是我一直在寻找的!可以逐行打印吗?比如:doggo=file2,file5鼠标=file4,file2。因为我有所有的指纹,但不知道谁属于哪个术语。只要从grepIt中删除l标志给我太多信息,我需要保留文件结果的请求行1,然后是文件结果的请求行2,要做到这一点,你需要阅读list.txt的每一行,然后用这一行执行grep。我为循环添加了一个额外的解决方案
# read contents of listfile in li
unset li && readarray li -u <"$listfile"

# add the content to new list so that it prints the list elements in new-lines
# also add a newline at top as it will be discarded by jq (in this case only)
list="$(echo; printf "%s" "${li[@]}";)"

# pass jq command
quoted_commands="$(jq -R 'reduce inputs as $line
        ([]; . + ["echo \($line) :; grep -rl \($line) \($dir); echo"])
        | (join("; "))' \
    --arg dir $dir <<< "$list")"
# the elements are read with reduce filter and converted to JSON Array of corresponding commands to execute
# the commands for all elements of list are joined with join filter

# trim quotes to execute commands properly
commands=$(sed -e 's/^"//' -e 's/"$//' <<< "$quoted_commands")

# run commands
eval "$commands"
signgle_quoted=${quoted%\"}
commands=${signgle_quoted#\"}
echo "$commands"
grep -rl -f list.txt C:\dirofcsv >> print.txt
awk '/^FILE -/ { fil=$3; # When the output start with "FILE -" set fil to the third space delimited field
                 next # Skip to the next line
               } 
               { arr[fil][$0]="" # Set up a 2 dimensional array with the search term (fil) as the first index and the name of the file the second
               } 
           END { for (i in arr) { # Loop through the array
                                  printf "%s => ",i; First print the search term in the format required
                                  for (j in arr[i]) { 
                                                      printf "%s,",j # Print the file name followed by a comma
                                                    } 
                                  printf "\n" # Print a new line
                                 } 
                }' <<< "$(while read line # Read list.txt line by line
                          do 
                             echo "FILE - $line"; Echo a marker for identification in awk
                             grep -l "$line" C:\dirofcsv  ; # Grep for the line
                          done < list.txt)" >> print.txt
awk '/^FILE -/ { fil=$3;next } { arr[fil][$0]="" } END { for (i in arr) { printf "%s => ",i;for (j in arr[i]) { printf "%s,",j } printf "\n" } }' <<< "$(while read line;do echo "FILE - $line";grep -l "$line"  C:\dirofcsv done < list.txt)" >> print.txt