Skip to content

Tag: awk

How to make a strict match with awk

I am querying one file with the other file and have them as following: File1: File2: This command: returns lines that overlap, BUT doesn’t have a strict match. Having a strict match, only Helen Stanley should have been returned. How do you restrict awk on a strict overlap? Answer With your shown samples pleas…

Using Awk to print the unavailable record only once

I am writing an awk script which looks like this inside: This is my file. This tries to print the else if method once, but instead, it prints for all of the lines that do not include the searched value. If I entered 20, my output looks like this: I have to use the awk command to print else if

Using awk to make changes to nth character in nth line in a file

I have written an awk command awk ‘NR==5 {sub(substr($1,14,1),(substr($1,14,1) + 1)); print “test.py”}’ > test.py This is trying to change the 14th character on the 5th line of a python file. For some reason this doesn’t stop executing and I have to break it. It also deletes t…

How to apply regex to specific column in awk

This will colorize the output of ls -lhAXF How to apply the color to specific type of item using regex, for example i want the folder to be green, the .config folder red, the regular file blue or something like that. folder – match $9 column containing ‘/’ in the end of word hidden folder &#…

converting 4 digit year to 2 digit in shell script

I have file as: Here the 1st column represents dates as YYYYMMDDHH I would like to write the dates as YYMMDDHH. So the desire output is: My script: It is printing Any help please. Thank you. Answer Please don’t kill me for this simple answer, but what about this: You simply cut the first two digits by s…