Skip to content
Advertisement

Tag: awk

Linux – flip last bottom lines only, with awk

We are currently learning some awk commands to manipulate/rearrange text on files. our original text goes like this..1998 It’s asking us to rearrange the columns (part one) which i already did.. but at the same time to flip the bottom two lines (part two) so that it looks like this again, i got the order and spacing taken care of,

sed/awk – remove a multiline block if it contains multiple patterns

In an xml file a multiline block is identified by <start></start>. I need to find and delete these multiline blocks if they contain a set of pattern in any order (pattern1, pattern2, etc). For example, in the following: if searching for pattern1 only, blocks 1, 3, 4 should be deleted if searching for pattern2 only, blocks 1, 2, 4 should

How to feed awk input from both pipe and file?

I was wondering how do I get awk to take a string from the pipe output and a file? I’ve basically have a chain of commands that eventually will spit out a string. I want to check this string against a csv file (columns separated by commas). Then, I want to find the first row in the file that contains

Edit field with date in .csv

I have .csv file with lines like this: and i need to change all date and time to this: I think it’s possible using awk and date but until now nothing worked. Answer Some perl: That removes the last 2 comma-separated fields from each line, deletes the fractional time and timezone, reformats the time and prints.

AWK remove duplicate line based on two conditions

I am trying to remove duplicates based on the value of the 2nd field. The lower value of the 2nd field should be retained, any line with repeated 1st field and higher 2nd field should be removed. This is an example of my raw data: Here is how it should be: So far, based on this post: I came up

compare the length of multiple files using awk or sed

I want to compare the number of lines of each file and choose the one that contains the maximum number of lines for example I will get as result Answer Alternative with lot’s of piping this script assumes the file names are under your control and space or _V won’t appear in the base names. Otherwise check out @Qualia’s version.

Parsing a config file inside shell script

I am trying to parse an ini file inside a shell script. name.conf file: I could parse the values by the command I wanted to know if there was some way by which I could group the contents of my config and parse it name.conf file: I just need the values in a shell array say names and print them

How to compute Cumulative values in Shell?

I would like to compute cumulative values from the below data file and writing them into columns after inserting a serial number. Where ifile.txt has 3 rows and 9 columns in this example. Desire output: Here first column is used for the serial number. So what I did is: I first converted into columns using Then I use awk I

Advertisement