awk

Data Conversion Using Sed or Awk - Name to Title

落花浮王杯 提交于 2021-02-10 07:17:07
问题 I have data in the below format: APP_OWNER : hari APP_AREA : Work:Business Area:AUS APP_ID : 124080 APP_OWNER : ari APP_AREA : Work:AUS APP_ID : 124345 I want the data to be converted to below format. APP_OWNER,APP_AREA,APP_ID hari,Work:Business Area:AUS,124080 ari,Work:AUS,124345 I can convert one line but how to do it with 3 lines at the same time? My Attempt with one line sed '0,/: /s//\n/' test.txt Original Question : Convert Rows to Columns Shell Script Regards 回答1: Here is an awk

Awk field separator

寵の児 提交于 2021-02-10 06:37:26
问题 I have a set of key value pairs in file on each line delimited by ":" I am fetching the key value pairs using awk as mentioned below after reading each line key=$(echo $LINE | awk -F " *: *" '{print $1}') value=$(echo $LINE | awk -F " *: *" '{print $2}') Problem is after if the value itself contains ":", it is further split and I will end up reading only value before ":" . How can I read the entire value 回答1: If you just want to split on the first : , it will be easier to use bash string

awk command to create sha2 of individual column and paste into new file

烈酒焚心 提交于 2021-02-10 06:24:07
问题 I have a file of having multiple rows. Using that original file I am creating one more files but in that new file i am taking only few columns of the original files. What I have to do is, instead of just picking few columns and pasting in new files, I need to create sha2 of first column and paste in new file as plain value also as well as sha2 value. Hope I am clear. This is the awk command I am using to do the same. awk -F '|' -v OFS='|' -v var="10|" '(NR - 1) != 0 {$2=var$2; print $2,$3,$4,

Using an array in AWK when working with two files

喜夏-厌秋 提交于 2021-02-10 06:14:19
问题 I have two files I merged them based key using below code file1 ------------------------------- 1 a t p bbb 2 b c f aaa 3 d y u bbb 2 b c f aaa 2 u g t ccc 2 b j h ccc file2 -------------------------------- 1 11 bbb 2 22 ccc 3 33 aaa 4 44 aaa I merged these two file based key using below code awk 'NR==FNR{a[$3]=$0;next;}{for(x in a){if(x==$5) print $1,$2,$3,$4,a[x]}; My question is how I can save $2 of file2 in variable or array and print after a[x] again. My desired result is : 1 a t p 1 11

Using an array in AWK when working with two files

[亡魂溺海] 提交于 2021-02-10 06:10:16
问题 I have two files I merged them based key using below code file1 ------------------------------- 1 a t p bbb 2 b c f aaa 3 d y u bbb 2 b c f aaa 2 u g t ccc 2 b j h ccc file2 -------------------------------- 1 11 bbb 2 22 ccc 3 33 aaa 4 44 aaa I merged these two file based key using below code awk 'NR==FNR{a[$3]=$0;next;}{for(x in a){if(x==$5) print $1,$2,$3,$4,a[x]}; My question is how I can save $2 of file2 in variable or array and print after a[x] again. My desired result is : 1 a t p 1 11

Using an array in AWK when working with two files

大憨熊 提交于 2021-02-10 06:04:15
问题 I have two files I merged them based key using below code file1 ------------------------------- 1 a t p bbb 2 b c f aaa 3 d y u bbb 2 b c f aaa 2 u g t ccc 2 b j h ccc file2 -------------------------------- 1 11 bbb 2 22 ccc 3 33 aaa 4 44 aaa I merged these two file based key using below code awk 'NR==FNR{a[$3]=$0;next;}{for(x in a){if(x==$5) print $1,$2,$3,$4,a[x]}; My question is how I can save $2 of file2 in variable or array and print after a[x] again. My desired result is : 1 a t p 1 11

Categorize a column and count the number of warnings in a column

拥有回忆 提交于 2021-02-09 11:15:14
问题 I am having a file called out.txt as below: Statement 1 Statement 2 Statement 3 Statement 4 The declaration is not done / Exp / * / This is expected The declaration is starting/started / St / * / This is not expected The declaration is not yet designed / Yt / & / This is a major one The declaration is confirmed / Exp / * / This is okay The declaration is not confirmed / Ntp / & / This is a major issue I need to sum up and categorize from column 3 (Statement 3), if it is * as Warning and if it

Categorize a column and count the number of warnings in a column

孤街浪徒 提交于 2021-02-09 11:13:13
问题 I am having a file called out.txt as below: Statement 1 Statement 2 Statement 3 Statement 4 The declaration is not done / Exp / * / This is expected The declaration is starting/started / St / * / This is not expected The declaration is not yet designed / Yt / & / This is a major one The declaration is confirmed / Exp / * / This is okay The declaration is not confirmed / Ntp / & / This is a major issue I need to sum up and categorize from column 3 (Statement 3), if it is * as Warning and if it

grep multiple patterns single file argument list too long

大憨熊 提交于 2021-02-08 23:41:13
问题 I am currently searching for multiple patterns in a file. The file is of 90GB in size, I am searching on a particular field(from position 6-17 in each line). I am trying to get all the lines that contain any of a particular list of numbers. The current syntax I am using is: grep '^.\{6\}0000000012345\|^.\{6\}0000000012543' somelargeFile.txt > outputFile.txt For small number of patterns this works. For a large number of patterns I get the "Argument list too long" error. One alternative I have

grep multiple patterns single file argument list too long

浪尽此生 提交于 2021-02-08 23:40:47
问题 I am currently searching for multiple patterns in a file. The file is of 90GB in size, I am searching on a particular field(from position 6-17 in each line). I am trying to get all the lines that contain any of a particular list of numbers. The current syntax I am using is: grep '^.\{6\}0000000012345\|^.\{6\}0000000012543' somelargeFile.txt > outputFile.txt For small number of patterns this works. For a large number of patterns I get the "Argument list too long" error. One alternative I have