Suppose I have csv file as follows:
SNo,Name,Country,uniqueness
1,abs,US,randomStringHavingUniqueString
2,xyz,UK,randomString
Now I want to get value of uniqueness only if it has UniqueString as part of it's value for uniqueness column.
The value I should get from this csv is randomStringHavingUniqueString because this string has substring UniqueString
CodePudding user response:
This command will get the desired result:
awk -F',' '$4 ~ "UniqueString" && NR > 1 {print}' file.csv
Output:
1,abs,US,randomStringHavingUniqueString
I am removing the header, you need to modify the command if you need the header.
CodePudding user response:
Using Miller, and runngin
mlr --c2n filter -S '$uniqueness=~"UniqueString"' then cut -f uniqueness input.csv
you have randomStringHavingUniqueString.
Some details:
filter -S '$uniqueness=~"UniqueString"'to apply string filter touniquenessfield;cut -f uniquenessto have in output onlyuniquenessfield.
