0
I have a file that contains comma separated strings. The strings may contain dots (i.e. not just alphanumeric characters). This is an example:
site1.com,Level1.2
site2.com,Level1.1,Level1.0,Level1.2
site3.com,Level1.2
site4.com,Level1.2,Level1.1,Level1.0,Levelv3
siteLevel1.2,Levelv2
Level1.2,Levelv2
I need to do search for the site names (please note that I do not have specific format for site name, i.e. it does not end with .com always so I should not conside how the first column look like)
I need the sites that ONLY contains specific string. In this example, Level1.2
exclusively (without Level1.1 nor Level1.0 not Level3 either before or after). Then print the result in a new file that matches the condition (only contains Level1.2). So the search key words are starting from the second column (I do not want search result that finds matching pattern in the site name).
So if I'm searching for Level1.2, the new file should contain:
site1.com,Level1.2
site3.com,Level1.2
But my command result in:
site1.com,Level1.2
site3.com,Level1.2
siteLevel1.2,Levelv2
Level1.2,Levelv2
If there is a site that contains Level1.2 in its name, it should not be counted as I do not care about the first column.
I tried this command and it works for me. The only thing is that I need the searching to ignore the occurrence of the search string in the first column.
awk '/Level1.2/ && !/Level1.1/ && !/Level1.0/ !/Level3/' myfile.txt > result.txt
Can't you just do
grep 'Level1.2$' myfile.txt
? – Arkadiusz Drabczyk – 2018-06-06T13:44:18.490What is the
$
for? and with grep, if it finds it in a line with other levels: Level1.1, I do not want it to count. I want to count it if it is the only one in the line (after the site name) without others. – user9371654 – 2018-06-06T13:49:52.623$
means end of line. How about:grep -E '^site[0-9]+\.com,Level1.2$' myfile.txt
? – Arkadiusz Drabczyk – 2018-06-06T13:52:28.710But end of line does not mean Lev1.2 is the only one in the line. It can be preceded by others. In this cas I do not want it. What I want is to make sure that Level1.2 is the only one strating from column2 onwards. i.e. I need to exclude the occurrence of any other level after column2. – user9371654 – 2018-06-06T13:54:57.373
Try the second
grep
command I posted. – Arkadiusz Drabczyk – 2018-06-06T13:55:50.590Sorry it does not do the purpose. The first column is not fixed format. I can not use
^site[0-9]+\.com
. My command is correct just please point to me how to search starting from the second column if you know. Thanks. – user9371654 – 2018-06-06T14:02:49.757