awk

AWK (unexpected newline or end of string)

心不动则不痛 提交于 2021-02-08 04:57:26
问题 I'm trying to execute bash script but I'm got stuck. data $ cat test.txt cat,command,for cp,command,for ls,command,to script #!/bin/bash CUT_FILE=test.txt TRN_GUID="1bcd1adf-2016-443b-9f00-2e4ce20726d7" LCTN_ID="8002" LCTN_NAME="TEST FILE" LCTN_ADDR1="This is test" cat $CUT_FILE | awk -F ',' '{ print '$TRN_GUID','$LCTN_ID','$LCTN_NAME','$LCTN_ADDR1',$1,$2 }' output -bash-3.2# sh test4 awk: cmd. line:1: { print 1bcd1adf-2016-443b-9f00-2e4ce20726d7,8002,TEST awk: cmd. line:1: ^ unexpected

Roundup function in Unix

元气小坏坏 提交于 2021-02-08 03:49:26
问题 I have a requirement as below 121.36 121.025 121.1 121.000 Desired output 122 122 122 121 Command used awk -F"." '{if($8>0){print $11}}' 回答1: What you're asking for is a ceil() (for "ceiling") function. It's important to include zero and negative numbers in your example when you're looking for any kind of rounding function as it's easy to get them wrong so using this input file: $ cat file 1.999999 1.0 0.000001 0 -0.000001 -1.0 -1.999999 we can test a ceil() function: $ awk 'function ceil(x,

Roundup function in Unix

≡放荡痞女 提交于 2021-02-08 03:49:03
问题 I have a requirement as below 121.36 121.025 121.1 121.000 Desired output 122 122 122 121 Command used awk -F"." '{if($8>0){print $11}}' 回答1: What you're asking for is a ceil() (for "ceiling") function. It's important to include zero and negative numbers in your example when you're looking for any kind of rounding function as it's easy to get them wrong so using this input file: $ cat file 1.999999 1.0 0.000001 0 -0.000001 -1.0 -1.999999 we can test a ceil() function: $ awk 'function ceil(x,

Interweave two files bash script

浪尽此生 提交于 2021-02-08 02:15:29
问题 I am trying to interweave two files that contain one sentence per line. I double spaced ( sed G ) the first file and I would like to incorporate the content of the second file into those empty lines. How can I interweave both files so that the 1st line of file B goes below the 1st line in file A, the 2nd line of file B below the 2nd line of file A, until it reaches the end ? Example: [line number|sentence number|sentence] 1 1 fileA 2 3 2 fileA 4 5 3 fileA 6 7 4 fileA Expected result: 1 1

Interweave two files bash script

依然范特西╮ 提交于 2021-02-08 02:11:22
问题 I am trying to interweave two files that contain one sentence per line. I double spaced ( sed G ) the first file and I would like to incorporate the content of the second file into those empty lines. How can I interweave both files so that the 1st line of file B goes below the 1st line in file A, the 2nd line of file B below the 2nd line of file A, until it reaches the end ? Example: [line number|sentence number|sentence] 1 1 fileA 2 3 2 fileA 4 5 3 fileA 6 7 4 fileA Expected result: 1 1

Print rows with condition on field data

天涯浪子 提交于 2021-02-07 20:18:36
问题 I have file with data cell input out type fun level AI20 A1,A2 Z comb ((A1A2)) 2 IA2 A1,A2,A3 Z comb ((!A1A2)A3) 3 XOR A1,A2,B1 Z comb (((A1A2)B1) 3 IAD A1,A2,A3 Z comb (!((A1A2)A3)) 3 INV I1 ZN comb (!I1) 1 BUF A1,A2,A3,B1 Z comb (!(((A1A2)A3)B1)) 4 From this data, I want to print rows whose level field (6th column) gives sum 7 together. here to get level sum 7 we can select AI2O , BUF , INV rows giving level sum as 2 + 4 + 1 = 7 and print them Or can select XOR , IAD , INV giving sum 3 + 3

Awk: Splitting file on nth occurence of delimiter, wrong first split file

可紊 提交于 2021-02-07 19:54:05
问题 I want to split a text file like the one pasted below (sorry for the length), on every n occurence of ">". For example, every 2nd occurrence of ">", but I need to able able to change that number. test_split.txt: >eeefkdfn a a a >c 4ufjdhf b b b b > c c > c d d d d d >3 >cr >c3 e e e e e > 5 f f f f >cr g g g g > cr dkjfddf h h h h So I want to have output files this these (only showing the first two): file_1.txt: >eeefkdfn a a a >c 4ufjdhf b b b b file_2.txt: > c c > c d d d d d etc. Question

Awk: Splitting file on nth occurence of delimiter, wrong first split file

帅比萌擦擦* 提交于 2021-02-07 19:53:13
问题 I want to split a text file like the one pasted below (sorry for the length), on every n occurence of ">". For example, every 2nd occurrence of ">", but I need to able able to change that number. test_split.txt: >eeefkdfn a a a >c 4ufjdhf b b b b > c c > c d d d d d >3 >cr >c3 e e e e e > 5 f f f f >cr g g g g > cr dkjfddf h h h h So I want to have output files this these (only showing the first two): file_1.txt: >eeefkdfn a a a >c 4ufjdhf b b b b file_2.txt: > c c > c d d d d d etc. Question

How do strongly typed regexp constants work in GNU Awk?

随声附和 提交于 2021-02-07 17:31:21
问题 Strongly typed regexp constants is a handy tool that GNU Awk has. It is documented in GNU Awk User's Guide -> 6.1.2.2 Strongly Typed Regexp Constants and in there you can find interesting examples. From reading it, and comments to an answer I made up some examples that show those: $ cat file he;llo ho are you; $ gawk -v patt='@/;/' '$0 ~ patt' file # it prints those lines containing ";" he;llo you; In this case, we pass the pattern ";" with @/;/ and so it prints all the lines that contain ";"