awk

Insert File Contents One Line Before Match While Escaping Backslash

我与影子孤独终老i 提交于 2020-01-05 04:00:17
问题 I recently asked a similar question How To Insert File Contents After Line Match While Escaping Backslash only to realize I need to do the opposite. Using the code from that question, I have tried: sed '/<\\tag>/i file2' file1 2nd attempt: awk '/<\\tag>/{print;system("cat File2.txt");before} 1' File1.txt However, I'm unable to get it to insert one line before the match. Example: File1.txt Hello <[World!]> 1 Hello <[World!]> 2 File2.txt: <thanks> <tag> <example> <new> <\new> <\example> <\tag>

Removing lines with consecutive pairs

帅比萌擦擦* 提交于 2020-01-05 03:46:08
问题 I have a text file with a lot of number combinations. It looks like this: 1 2 3 4 5 6 1 2 3 4 5 7 1 2 3 4 5 8 1 2 3 4 5 9 1 2 3 4 5 10 Every line has 6 numbers with a space between each number. Numbers go from 1 to 37. I need an AWK command to remove any line with 2 or 3 consecutive pairs. For example: 1 2 6 9 13 14 4 5 18 19 25 26 Thanks! 回答1: awk '{pairs = 0; for (i = 1; i < NF; i++) if ($i + 1 == $(i + 1)) pairs++; if (pairs != 2 && pairs != 3) print}' input_file 来源: https://stackoverflow

Awk code to select multiple patterns

偶尔善良 提交于 2020-01-05 03:27:08
问题 This is my input file, say modified.txt ------------------------------------------------------------------------ r4544 | n479826 | 2012-08-28 07:12:33 -0400 (Tue, 28 Aug 2012) | 1 line Changed paths: M /branches/8.6.0/conf/src/main/config/RTSConfig.xml CET-402: some text comment ------------------------------------------------------------------------ r4550 | n479826 | 2012-09-04 05:51:29 -0400 (Tue, 04 Sep 2012) | 1 line Changed paths: M /branches/8.6.0/conf/src/main/config/RTSConfig.xml M

AWK is it possible to read a time field and use it for sorting?

淺唱寂寞╮ 提交于 2020-01-05 03:06:30
问题 I have two files and I need to sort and merge the rows based on the time column: File A: "2014-02-26 16:03:04" "Login Success|isNoSession=false" id=csr,ou=user,dc=openam,dc=forgerock,dc=org 7efb2f0e035a0e3d01 10.17.174.30 INFO dc=openam,dc=forgerock,dc=org "cn=dsameuser,ou=DSAME Users,dc=openam,dc=forgerock,dc=org" AUTHENTICATION-100 DataStore "Not Available" 10.17.174.30 File B: "2014-02-26 16:02:27" "Login Failed" dennis "Not Available" 10.17.174.30 INFO dc=openam,dc=forgerock,dc=org "cn

Awk - Compare every line to find a duplicate field, and add some wording to the end of line

风格不统一 提交于 2020-01-05 03:03:22
问题 I have a file like this file, and I am trying to verify one field of each line, and add some wording if that field has a duplicate earlier in the file. \\FILE04\BUET-PCO;\\SERVER24\DFS\SHARED\CORP\ET\PROJECT CONTROL OFFICE;/FS7_150a/FILE04/BU-D/PROJECT CONTROL OFFICE;10000bytes;9888;;; \\FILE12\BUAG-GOLDMINE$;\\SERVER24\DFS\SHARED\CAN\AGENCY\GOLDMINE;/FS3_150a/FILE12/BU/AGENCY/GOLDMINE;90000bytes;98834;;; \\FILE12\BUGB-BUSINTEG$;\\SERVER24\DFS\SHARED\CAN\GB\BUSINTEG;/FS3_150a/FILE12/BU/GB

Join two files including unmatched lines in Shell

孤街醉人 提交于 2020-01-05 02:50:08
问题 File1.log 207.46.13.90 37556 157.55.39.51 34268 40.77.167.109 21824 157.55.39.253 19683 File2.log 207.46.13.90 62343 157.55.39.51 58451 157.55.39.200 37675 40.77.167.109 21824 Below should be expected Output.log 207.46.13.90 37556 62343 157.55.39.51 34268 58451 157.55.39.200 ----- 37675 40.77.167.109 21824 21824 157.55.39.253 19683 ----- I tried with the below 'join' command - but it skips the missing line join --nocheck-order File1.log File2.log outputting like below (not as expected) 207.46

In a column of numbers, find the closest value to some target value

穿精又带淫゛_ 提交于 2020-01-05 02:30:35
问题 Let's say I have some numerical data in columns, something like 11.100000 36.829657 6.101642 11.400000 36.402069 5.731998 11.700000 35.953025 5.372652 12.000000 35.482082 5.023737 12.300000 34.988528 4.685519 12.600000 34.471490 4.358360 12.900000 33.930061 4.042693 13.200000 33.363428 3.738985 13.500000 32.770990 3.447709 13.800000 32.152473 3.169312 I also have a single target value and a column index. Given this set of data, I want to find the closest value to the target value in the

bash to merge lines in a file

跟風遠走 提交于 2020-01-04 16:58:38
问题 I want convert this text: qa-ops01.mysite.com /dev/mapper/sys-home 58G 26G 30G 47% /home /dev/mapper/sys-tmp 3.9G 2.3G 1.5G 61% /tmp qa-ops02.mysite.com /dev/mapper/sys-home 58G 26G 30G 47% /usr /dev/mapper/sys-tmp 3.9G 2.3G 1.5G 61% /var qa-ops03.mysite.com /dev/mapper/sys-home 58G 26G 30G 47% /lib /dev/mapper/sys-tmp 3.9G 2.3G 1.5G 61% /etc to this one: qa-ops01.mysite.com /dev/mapper/sys-home 58G 26G 30G 47% /home qa-ops01.mysite.com /dev/mapper/sys-tmp 3.9G 2.3G 1.5G 61% /tmp qa-ops02

Awk substring a single character

纵饮孤独 提交于 2020-01-04 14:07:11
问题 Here is columns.txt aaa bbb 3 ccc ddd 2 eee fff 1 3 3 g 3 hhh i jjj 3 kkk ll 3 mm nn oo 3 I can find the line where second column starts with "b": awk '{if(substr($2,1,1)=="b") {print $0}}' columns.txt I can find the line where second column starts with "bb": awk '{if(substr($2,1,2)=="bb") {print $0}}' columns.txt Why oh why can't I find the line where the second character in the second column is "b"?: awk '{if(substr($2,2,2)=="b") {print $0}}' columns.txt awk -W version == GNU Awk 3.1.8 回答1:

Searching number in file

北慕城南 提交于 2020-01-04 13:35:23
问题 How to write program in awk or in something more appropriate, if it is needed, that will search and write numbers? I have a file 0.0000000 -0.0000000 -0.0000000 -0.0000000 0.0000000 -0.0000000 0.0000000 -0.0000000 -0.0000000 -0.0000000 -0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 -0.0000000 0.0000000