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 please try following. You were on right

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

Remove eveything before including colon and replace comma to newline

I am looking just to accommodate my query into one-liner. I have a below file content where i want to remove all before last colon(:) including itself and then replace comma(,) into newline to get the desired results. these all comma separated values are linux user ID’s File content: Already tried: working solution: result: Is there a better trick, please

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 “”}’ > 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 the contents of the file. Sample input: ` Output: Answer Get away from

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 – match $9 column containing

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 showing character 3