Skip to content

Tag: awk

Conditional append of strings on fields in a csv file

I am trying to convert a csv file like below with bash scripts. Headers and structures are always the same. Source csv file: Conditional values (will change depending on the requirements) Now I am trying to get the following result without the first row and values are now separated by spaces if each header ma…

Using awk to parse and transform the following log

I have a log like this: I want to parse this log file and get all the following lines: Then I want to transform those lines into the following format for plotting: Here is my awk code: The thing I don’t like for this solution is: I must count manually the index of tokens generated by awk. I prefer a

How to split a single XML file into multiple based on tags

I have an XML file that have tags. I want to split files like this. Below is the code tried . But it is generating every single line into a new file I want to split this file based on ORDER tags alone as mentioned below Answer With any awk in any shell on every UNIX box: it’s obviously fragile

Recover informations from CSV files with my awk script

I have this CSV files : I create a little script that allow me to recover the informations from my csv and to place them like this : My script is : But the result is : Or I want : Can you tell me why my script doesn’t works and why floats are not taken into account ? Thank

Linux/Shell slicing a large text file

Given File1 File2 I wish to make a method that basically does this So given a uniquename from file1 it will use its key from file2 to get what it’s link to. If it doesn’t find uniquename do nothing. MY ATTEMPT Answer The cut utility was designed for this type of data:

find matching text and replace next line in yml

I’m trying to find a line in a yml configuration file and replace the next line with a specific value. I tried sed, but it seems it is not replacing or not able to find the pattern. Below is the snippit of that yml file I want to change port value to 14081 for applicationConnectors as there is another p…

How to find encapsulating function name from line number

I am looking at a log file which just tells me the filename and the line number inside that file that has the Error. What I am interested is knowing the encapsulating function. For example, here are the contents of the log file and here are the contents of the file foo.file Based on the above log file, I want

How To Replace Strings With X to Y Characters

I have data similar to the following: I am looking for a way to replace strings in field 2. If the number does not have 10-11 characters, I would like to replace it with 12223334444 so the output would be: My original thought was to use cut to get the second field and then use grep “[1-9]” or some…