awk

How to subtract column values by the first row with awk?

How to subtract column values by the first row with awk? The input file is lines of "id number1 number2 count", both number1 and number2 are ascendant. Barcode000000 48521 1855 0 Barcode000001 48621 1855 0 Barcode000002 48721 1855 1 Barcode000003 48821 1855 0 Barcode000004 48921 1955 20 Barcode000005 49021 1955 0 Now I use awk …

Total answers: 3

awk on date conditions

awk on date conditions I am trying delete rows from a person.csv (below) for the condition that person who are not born in last 1 year: Dataset1: "Index","User Id","First Name","Last Name","Date of birth","Job Title" "1","9E39Bfc4fdcc44e","new, Diamond","Dudley","06 Dec 1945","Photographer" "3","32C079F2Bad7e6F","Ethan","Hanson","08 Mar 2014","Actuary" "2","aaaaaaa, bbbbbb","Grace","Huerta","21 Jan 2023","Visual merchandiser" So, the expected output would look like(last row got …

Total answers: 5

Remove duplicates by adding numerical suffix

Remove duplicates by adding numerical suffix How do I append a numerical suffix to lines to remove duplicates? Pseudo code: if currLine.startsWith("tag:") x = numFutureLinesMatching(currLine) if (x > 0) currLine = currLine + ${x:01} Input file tag:20230901-FAT val:1034 tag:20230901-FAT val:1500 tag:20230901-LAX val:8934 tag:20230901-SMF val:2954 tag:20230901-LAX val:1000 tag:20230901-FAT val:1500 Desired output tag:20230901-FAT-02 val:1034 tag:20230901-FAT-01 val:1500 tag:20230901-LAX-01 …

Total answers: 4

awk add a column if it doesn't exist

awk add a column if it doesn't exist I would like to add a column 3 (description) if it does not exist in a ‘;’ delimited file. example; #Gene;Transcripts;Description;Group gene1;G1a,G1b,G1c;gene1 is a good gene;6 gene2;G2a,G2b,G2c;gene2 is a funny gene;3 gene3;G3a,G3b;4 gene4;G4a;gene4 description;5 gene5;G5a,G5b;6 Expected output #Gene;Transcripts;Description;Group gene1;G1a,G1b,G1c;gene1 is a good gene;6 gene2;G2a,G2b,G2c;gene2 is a funny …

Total answers: 4

How can I format this awk command?

How can I format this awk command? $ echo "$(lastlog | grep $USER | awk ‘{print $(NF-5)" "$(NF-3)" "$(NF-4)" "$(NF-2)" "$(NF-1)" "$(NF-0)}’)" Thu 7 Sep 05:56:35 +0100 2023 I want to replace the +0100 bit with BST or GMT if the value is +0000 (I am aware that this output is probably dependent on the …

Total answers: 1

awk doesnt add columns to tab delim file

awk doesnt add columns to tab delim file I’m using the following code to add two new columns (15 and 16) to a tab delim txt file based on calculations from other existing columns. Problem: new column data is shown in terminal but file is not updated with columns. when sent to another file (code …

Total answers: 3

awk – print $0 ignores OFS

awk – print $0 ignores OFS I want to output every Column / Field, but when I do it with the $0 variable, it ignores the default OFS variable which is a single space, so the :‘s still get printed. Here is the command I tried: cat /etc/passwd | awk -F’:’ ‘{print $0}’ Given this …

Total answers: 2

Grep Multiple Pattern located in different lines and print in the same line

Grep Multiple Pattern located in different lines and print in the same line I’m trying to find a way to grep information in the file that located in the different lines and one of the pattern is contain pattern of date and time. below is the input unwantedtext unwantedtext unwantedtext unwantedtext 8/1/2022 6:15 (1st required …

Total answers: 5

Replace Values in a String in an Output File with a String from a Source File

Replace Values in a String in an Output File with a String from a Source File I need to replace the values, specifically the values between the equals sign ‘=‘ and the colon ‘:‘ in an existing file called zoo.cfg, at the bottom of this file i.e., … Server.1=10.42.227.70:2891:3881 Server.2=10.42.229.63:2891:3881 Server.3=10.42.234.18:2891:3881 … With values from …

Total answers: 1

Need to Extract String from Result of awk Command and Copy to Output File

Need to Extract String from Result of awk Command and Copy to Output File I want to extract strings from a terraform.tfstate file. I am running the following ack command: … awk ‘/nifi1a/{x=1}x&&/private_ip/{print;exit}’ terraform.tfstate Running this command results in: "private_ip": "10.42.229.45", I would like to extract the string between the second set of double quotes …

Total answers: 2

How to convert all text into 1 except "0"s and first two fields in a csv file?

How to convert all text into 1 except "0"s and first two fields in a csv file? I have several large.csv files that I’d like to convert to binary (1 and 0) format. In which all cells containing text would become 1 and 0 would remain 0, except first two fields. head Test.csv Iss1,1,0,0,Hsapiens-I34,0,0,0,Mmusculus-H01,0,0 Iss1,11,0,Scerevisiae-U09,Hsapiens-I05,0,0,0,0,0,0 …

Total answers: 5

Extract data which is inside square brackets and separated by comma

Extract data which is inside square brackets and separated by comma I have data like: [‘/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/’, ‘/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/’, ‘/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/’, ‘/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/’, ‘/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4/’, ‘/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5/’, ‘/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom6/’, ‘/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom7/’, ‘/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom8/’, ‘/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom9/’] I want each value without quote one per line so that I can pipe it to another command, like: /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/ …. awk -F'[][]’ ‘{print $2}’ removes the square brackets. …

Total answers: 2

Changing non-standard date timestamp format in CSV using awk/sed

Changing non-standard date timestamp format in CSV using awk/sed I have a csv with a few hundred thousand lines and I’m trying to change the date format in the second field. I should also add the second field is sometimes not populated at all. The deplorable input format is DayofWeek MonthofYear DayofMonth Hour:Minute:Second Timezone Year …

Total answers: 4

Programmatically change field separator (FS) and recompute current record in gawk?

Programmatically change field separator (FS) and recompute current record in gawk? I want to change the field separator (FS) only for a specific record, and I want the record ($0), fields ($N), and number of fields (NF) to be recomputed using the new field separator. But it doesn’t seem to work. Example: Here I have …

Total answers: 2

is there an awk column offset?

is there an awk column offset? I am trying to create a command that works with the output to check the partition type and name. I have just discovered a solution using awk or perhaps sfdisk? Here’s my base output: root@debian:/home/si# sudo sfdisk -l /dev/sda –quiet | awk ‘{print $0}’ Périphérique Amorçage Début Fin Secteurs …

Total answers: 2

Linux bash awk print word with special letter

Linux bash awk print word with special letter I have a URL: www.google.com/word/word1/word_2/word3/word4 I would like to use awk to print only the words that contain the _ special character. Sometimes the folder hierarchy may change: www.google.com/word/word1/word2/word3/word_4 I was using this, but sometimes the folders are above $6: folder=$(echo "$url" | awk -F/ ‘{print $6}’) …

Total answers: 3