I am trying to return a list of the months that files were created using the following code. I am using the below code to validate each output. However as you can see from my output: Output of ls|grep I end up with 1 record showing no date. Also both January and December are short by 1. Can anyone assist?
Tag: awk
Change some field separators in awk
I have a input file 1.txt and I want an output file: out.txt I want to replace the first two ‘:’ in 1.txt with ‘||o||’, but with the script I am using But it is not giving the expected output. Any help would be highly appreciated. Answer Following sed may also help you in same. Explana…
Matching files using awk in linux
I have 2 files: 1.txt: 2.txt: I want 2 files as output: One is result.txt which contains lines from 2.txt whose match is in 1.txt and another is left.txt which contains lines from 1.txt whose match is not in 2.txt Expected output of both files is below: result.txt left.txt I tried 1-2 approaches with awk but …
Merge two files using awk in linux
I have a 1.txt file: A 2.txt file: FS for 1.txt is “||o||” and for 2.txt is “:” I want to merge two files in a single file result.txt based on the condition that the 3rd column of 1.txt must match with 1st column of 2.txt file and should be replaced by the 2nd column of 2.txt file. The…
Set an external variable in awk
I have written a script in which I want to count the number of columns in data.txt . My problem is I am unable to set the x in awk script. Any help would be highly appreciated. data.txt file: Expected output: My output: Answer You just cannot import variable set in Awk to a shell context. In your example the
how to count repeated sentence in Shell
My expected result is like as below: I have found a way to deal with the issues, but my code is a little noisy. I was wondering if you could show me more high-efficiency way to achieve the goal.Thanks a lot. Answer If you’re lines are not already grouped, then you could use This will consume a lot of me…
Compare multiple columns for each row
Using a csv file, i will like to compare multiple columns to check if all values are the same or not. First row are the headers First column is the label The constant values should be from column 2 to the end ( can be 100 columns ) for the example i put only 8 columns. The purpose is to
Separate Text file to columns by ;
Please I have a text file separated by spaces. I would like to output it to columns separated by ; example Input I use this code My output Output desired. Appreciate your help. Answer $1=$1 is a trick to rebuild $0 with the new separator OFS=’;’.
parsing complex string using shell script
I’m trying the whole day to find a good way for parsing some strings with a shell script. the strings are used as calling parameter for some applications. they looks like: I’m only allowed to use shell-script. I tried to use some sed and cut commands but nothing works fine. My tries are like: that…
Extract Column(s) from text file having Multi Character Delimiter i.e. “%$%”
I have tried different solution for the problem given on the forum but doesn’t work for the specified Delimiter %$%, I need to extract one specific column from the file containing 200+ columns. I tried the following: Answer The symbol $ is a special character in a regex, so you need to escape it with a …