awk

How to use find command with sed and awk to remove duplicate IP from files

二次信任 提交于 2020-01-05 08:06:36
问题 Howdie do, I'm writing a script that will remove duplicate IP's from two files. For example, grep -rw "123.234.567" /home/test/ips/ /home/test/ips/codingte:123.234.567 /home/test/ips/codingt2:123.234.567 Ok, so that IP is in two different files and so I need to remove the IP from the second file. The grep gives me the file path and the IP address. My thinking: store the file path in a variable with awk and then use find to go to that file and use sed to remove the duplicate IP, so I changed

How to pass BASH shell variables into AWK statement

陌路散爱 提交于 2020-01-05 07:29:22
问题 I want to pass 2 shell (bash) variables from into an awk statement. In this example the variables are marker1 and marker2 ubuntu@ubuntutest:/tmp$ echo $marker1 ###___showhost___### ubuntu@ubuntutest:/tmp$ echo $marker2 ###___showhostset___### ubuntu@ubuntutest:/tmp$ The script will extract all the lines of text between to different strings/markers ($marker1 and $marker2) from text file - file.in ubuntu@ubuntutest:/tmp$ cat file.in ###___showhost___### Id Name Persona -WWN/iSCSI_Name- Port 115

sed/awk/perl: find a regex, copy 5 columns of this line and paste to it at the beginning of the next lines

↘锁芯ラ 提交于 2020-01-05 06:33:26
问题 I have following lines: 057 - - No adod3 stptazlqn 10 753 tlm 10 027 stp 10 021 12 - - No azad1 bbcz 30 12 03085 - - No azad1 azad1222 xxaz 1 12 azzst 1 12 hss 2 12 what I need to do is: Find lines starting with a number [0-9]. Copy the first 5 columns separated by a space ' '. Paste it in the next lines not starting with a number. 057 - - No adod3 stptazlqn 10 753 057 - - No adod3 tlm 10 027 057 - - No adod3 stp 10 021 12 - - No azad1 12 - - No azad1 bbcz 30 12 03085 - - No azad1 azad1222

How do I remove the line break from alternate lines in an ASCII file

末鹿安然 提交于 2020-01-05 05:42:05
问题 I have an ASCII file that contains data as follows 459999XXX9998882 WTD CCD 3,500.00- 0.00 3,500.00- 0.00 0.00 09/07/17 23:00:07 999999999999 000000000000 EONCO024 GTUR BR AND PARDES APIN 459999XXX9998883 WTD CCD 400.00- 0.00 400.00- 0.00 0.00 09/07/17 23:00:12 999999999999 000000000000 EOMCO015 P.G ROAD, ANNA HOT SECU TLIN 29999XXX99988829 INQ CCD 0.00 0.00 0.00 0.00 0.00 09/07/17 23:00:41 999999999999 000000000000 EOMCO010 PUNA KUMBHARIA ROAD, SUR GJIN 5459999XXX999888 INQ SAV 0.00 0.00 0

why isn't this awk script behaving as expected?

会有一股神秘感。 提交于 2020-01-05 04:50:13
问题 I have the following test script /^[^a-zA-Z0-9]/ { DATEd[$3] = $1 } END { print " \"data\": [" for (i = 0 ; i <= 5; i ++ ) { { print " [" i ", \"" DATEd[i] "\"],"} } print " ]" } And are reading from this text file 2011-01-22 22:12 P16A22_110114072915 22 1312 75 13.55 1399 2011-01-22 22:12 P16A22_110114072915 22 1312 75 13.55 1399 2011-01-22 22:12 P16A22_110114072915 22 1312 75 13.55 1399 2011-01-22 22:12 P16A22_110114072915 22 1312 75 13.55 1399 2011-01-22 22:12 P16A22_110114072915 22 1312

bash: all combinations of lines

随声附和 提交于 2020-01-05 04:48:25
问题 I have the following file (this is semicolon delimited; the real file is tab-delimited) abc;173959;172730 def;4186657;4187943 ghi;4703911;4702577 jkl;2243551;2242259 and I want to combine each line with each, so that my output would be: abc;173959;172730;def;4186657;4187943 abc;173959;172730;ghi;4703911;4702577 abc;173959;172730;jkl;2243551;2242259 def;4186657;4187943;ghi;4703911;4702577 def;4186657;4187943;jkl;2243551;2242259 ghi;4703911;4702577;jkl;2243551;2242259 The order is not important

Bash replace in CSV multiple columns

左心房为你撑大大i 提交于 2020-01-05 04:21:11
问题 I have the following CSV format: data_disk01,"/opt=920MB;4512;4917;0;4855","/=4244MB;5723;6041;0;6359","/tmp=408MB;998;1053;0;1109","/var=789MB;1673;1766;0;1859","/boot=53MB;656;692;0;729" I would like to take from each column, except the first one, the last value from the array, like this: data_disk01,"/opt=4855","/=6359","/tmp=1109","/var=1859","/boot=729" I have tried something like: awk 'BEGIN {FS=OFS=","} {if(NF==!1);gsub(/\=.*/,",")} 1' Just the string, I managed to do it with: string="

Using gawk in a batch file I am having trouble reformatting lines from format A to format B

对着背影说爱祢 提交于 2020-01-05 04:14:12
问题 I have a compiler which produces output like: >>> Warning <code> "c:\some\file\path\somefile.h" Line <num>(x,y): warning comment For example: >>> Warning 100 "c:\some\file\path\somefile.h" Line 10(5,7): you are missing a ( >>> Warning 101 "c:\some\file\path\file with space.h" Line 20(8,12): unexpected char a I need to get the into the format (for MSVS2013): <filename-without-quotes>(<line>,<column>) : <error|warning> <code>: <comment> e.g. using the first example from above: c:\some\file\path

using powershell like awk to get the console user

大憨熊 提交于 2020-01-05 04:06:48
问题 I basically want to use powershell and get the console user like "query session | findstr console | awk '{print $2}'" but not using awk, but I can't get it to work. $out = query session | findstr console # good $consoleuser = $out.split('\s+')[1] # doesn't work $out looks something like: >console joe 2 Active $consoleuser ends up being: ole joe 2 Active 回答1: .Split() is a .Net string method, it doesn't use regexes. -split is the PowerShell operator and uses regexes. And calling out to findstr

Host file make a unique file for all servers

元气小坏坏 提交于 2020-01-05 04:06:12
问题 I have many hosts files. I collect them from all servers and i put them together in host_files.txt and then I must make one hosts file for all servers. I do this command to make a unique file, but some rows share the same ip address or hostname. awk '!a[$0]++' host_files.txt Here is my host_files.txt #backup server IPs 95.23.23.56 95.23.23.57 #ftp server IPs 45.89.67.5 45.89.67.3 #apache 12.56.35.36 12.56.35.35 #ftp server IPs 95.23.23.50 #apache 12.56.35.37 I want to output file, but I need