I am a self-confessed beginner level when it comes to RHEL and I can navigate around, find things, run things etc. And I only have basic permissions on my DEV, INT, PROD and BCP servers at my client as most of my time is taken up in complex development. I use ksh scripts to launch Tomcat, and for the new
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
Filtering access logs by last 15 minutes with awk not working when there are no entries
I have an apache access log with the below format and I’m trying to use the awk command to filter out the requests by the last 15 minutes. It works fine when there are entries but returns everything when there are none found in the last 15 minutes. Access log format Answer It’s not possible to compare date directly in
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 the contents of the file. Sample input: ` Output: Answer Get away from
How to extract strings by using awk on multiple text files and summaries to one file
I have 70 input files, file names are as like slurm-22801576.out, slurm-22801573.out, slurm-26801571.out, and so on. I want to extract all desired strings to one file. So I did the following but I was able to do so for one file only. How to do that on multiple files? But my output file has only one row Inside each input
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
Awk average of column by moving difference of grouping column variable
I have a file that look like this: File is sorted by column 3. I want the average of 4th column grouped by column 3 every 0.5 unit apart. For example it should output like this: I can print all positions without average like this: But I am not able to figure out how to print average of 4th column.