awk

deleting selected lines from data file

做~自己de王妃 提交于 2020-01-06 10:53:55
问题 This question is continuation from my earlier post titled "selecting digits from regular expression". Below is the sample data as posted in the earlier post. DONOR ACCEPTORH ACCEPTOR atom# res@atom atom# res@atom atom# res@atom %occupied distance angle | 4726 59@O12 | 1487 19@H12 1486 19@O12 | 85.66 2.819 ( 0.18) 21.85 (12.11) | 1499 19@O15 | 1730 22@H12 1729 22@O12 | 83.15 3.190 ( 0.31) 22.36 (12.73) | 1216 16@O22 | 1460 19@H22 1459 19@O22 | 75.74 2.757 ( 0.14) 24.55 (13.66) | 4232 53@O25 |

print all rows following matched row

廉价感情. 提交于 2020-01-06 08:50:11
问题 How can I print all rows after matching pattern in nth row, but ignore all before matched row including the matching row, here is an example : row1 something in this row row2 something in this row row3 something in this row row4 don't need to match the whole line, something like java String.contains() row5 something in this row row6 something in this row row7 something in this row row8 something in this row row9 something in this row row10 something in this row I'm looking to print lines

Awk code with associative arrays — array doesn't seem populated, but no error

只愿长相守 提交于 2020-01-06 08:48:29
问题 Question: Why does it seem that date_list[d] and isin_list[i] are not getting populated, in the code segment below? AWK Code (on GNU-AWK on a Win-7 machine) BEGIN { FS = "," } # This SEBI data set has comma-separated fields (NSE snapshots are pipe-separated) # UPDATE the lists for DATE ($10), firm_ISIN ($9), EXCHANGE ($12), and FII_ID ($5). ( $17~/_EQ\>/ ) { if (date[$10]++ == 0) date_list[d++] = $10; # Dates appear in order in raw data if (isin[$9]++ == 0) isin_list[i++] = $9; # ISINs appear

Remove blank line from awk output

不羁岁月 提交于 2020-01-06 08:28:10
问题 I am trying to remove leading whitespace from awk output. When I use this command, a leading whitespace is displayed. diff test1.txt test.txt | awk '{print $2}' output: asdfasdf.txt test.txt weqtwqe.txt How can I remove the leading whitespace using awk? Thanks in advance 回答1: if you want to print the lines where $2 exists you can do it conditionally on number of fields awk 'NF>1{print $2}' will do. 来源: https://stackoverflow.com/questions/32789063/remove-blank-line-from-awk-output

Parsing log lines using awk

戏子无情 提交于 2020-01-06 08:07:08
问题 I have to parse some information out of big log file lines. Its something like abc.log:2012-03-03 11:12:12,457 ABC[123.RPH.-101] XYZ: Query=get_data @a=0,@b=1 Rows=10Time=100 There are many log lines like above in the logfiles. I need to extract information like datetime i.e. 2012-03-03 11:12:12,457 job details i.e. 123.RPH.-101 Query i.e. get_data (no parameters) Rows i.e. 10 Time i.e. 100 So output should look like 2012-03-03 11:12:12,457|123|-101|get_data|10|100 I have tried various

truncate decimal places in column

一笑奈何 提交于 2020-01-06 07:46:47
问题 How to truncate decimal places in column? I want to print first comlumn, the second column, which decimal places will be cut (not round) to 4 places a then a text. Thank you Input file 56603.6153 2.212645 56603.6156 2.215645 56603.6158 2.210845 56603.6161 2.216175 56603.6166 2.204975 56603.6168 2.195275 56603.6171 2.219587 56603.6173 2.210778 56603.6176 2.199887 I tried this awk -F. '{print $1"."substr($1,5,4)" " $2"."substr($2,1,4)}' file the output was: 56278.8 5545 2.5545 56278.8 5549 2

truncate decimal places in column

霸气de小男生 提交于 2020-01-06 07:46:31
问题 How to truncate decimal places in column? I want to print first comlumn, the second column, which decimal places will be cut (not round) to 4 places a then a text. Thank you Input file 56603.6153 2.212645 56603.6156 2.215645 56603.6158 2.210845 56603.6161 2.216175 56603.6166 2.204975 56603.6168 2.195275 56603.6171 2.219587 56603.6173 2.210778 56603.6176 2.199887 I tried this awk -F. '{print $1"."substr($1,5,4)" " $2"."substr($2,1,4)}' file the output was: 56278.8 5545 2.5545 56278.8 5549 2

How to replace a word through a variable after searching?

♀尐吖头ヾ 提交于 2020-01-06 06:48:13
问题 I have a problem like this. In a text file(which is called sampleText.txt) has the web url like this, webURL = "localhost.com"; I want to change this value using a bash script. But I tried with this my script, bt it did not worked, here is my script, #!/bin/bash URL=$(awk -F\" '/^webURL/{print $2}' sampleText.txt) echo $URL if [ "$URL" != "www.google.com" ]; then shopt -s globstar for file in sampleText.txt do sed -i.bak 's/$URL/www.google.com/g' $file done fi I hope you will help me. Any

How to replace a word through a variable after searching?

可紊 提交于 2020-01-06 06:48:11
问题 I have a problem like this. In a text file(which is called sampleText.txt) has the web url like this, webURL = "localhost.com"; I want to change this value using a bash script. But I tried with this my script, bt it did not worked, here is my script, #!/bin/bash URL=$(awk -F\" '/^webURL/{print $2}' sampleText.txt) echo $URL if [ "$URL" != "www.google.com" ]; then shopt -s globstar for file in sampleText.txt do sed -i.bak 's/$URL/www.google.com/g' $file done fi I hope you will help me. Any

Shell script to grep string and its value and produce output in another file

允我心安 提交于 2020-01-06 05:46:10
问题 I need to grep value of ErrCode, ErrAttkey and ErrDesc from the below Input file. and need to display as below in another file How can i do this using shell script? Required output ErrCode|ErrAtkey|ErrDesc 003010|A3|The Unique Record IDalreadyExists 008024|A8|Prepaid / Postpaid not specified Input File <TariffRecords><Tariff><UniqueID>TT07PMST0088</UniqueID><SubStat>Failure</SubStat><ErrCode>003010</ErrCode><ErrAttKey>A3</ErrAttKey><ErrDesc>The' Unique Record ID already 'Exists</ErrDesc><