awk's questions - Danish 1answer

4.143 awk questions.

ip a | egrep '([0-9]{1,3}\.){3}[0-9]{1,3}|enp0s' | grep -e 10 -e 172 -e 192 | awk '{print $2}' | awk '{gsub("/24", "");print}' | xargs The above command gives the output as: enp0s3: 10.0.2.15 enp0s8:...

I have a text file with multiple columns. I want to rearrange the cell position keeping the column number the same. Is there any Perl or command-line solution? INPUT FILE DESIRED OUTPUT

Is there any tool in Solaris UNIX (so no GNU tool available) to subtract dates? I know that in Linux we have gawk that can subtract one date from another. But in Solaris the maximum we have is nawk (...

patsplit vs split in gawk

3 answers, 691 views awk gawk
In the gawk manual, I found two functions patsplit and split. I am wondering what their differences are? I understand the purpose of split, but what is the purpose of patsplit? Thanks.

I have a text file with following contents $ cat foo.txt some text email@id.com 8903457923 2018-02-09 07:12 (Asia/Kolkata) again some text over here some more text again Message some text email@id....

I have 10GB files in which i want to count occurrence of some specific text i.e TY[0-9]. File format is like : ABC,2A,2018-07-06,2018-06-20 00:00:00 BCD,TY1,2018-07-06,2018-06-20 00:00:00 EFG,TY2,...

I have a text file like the one below although with almost many columns. I want to extract column names that have a specific proportion/number of TRUE values, for example columns with TRUE in 2 out of ...

File 1 abram,john,steve,mark,daniel,stokes 19,567,44,0,77,9 File 2 john,mark,skates 999,1,1 File 3 abram,stokes 55,66 File 4 abram,daniel,john,mark,skates,steve,stokes,yasmin 0,0,0,0,0,0,0,0 ...

So I was told to do last > lastloggedin which creates a file that shows the classes last login since the last system reboot, and now I am asked to write an Awk script which is named myawk that ...

I have a configuration script which does basically this: #!/bin/bash source vars.sh cat >foo.output <<EOF # some static stuff (many lines...) variable_bit=($SOME_VAR, $SOME_OTHER_VAR, ...) ...

I have a .csv data file which I have manipulated to look like this: -------------PATH AND FILE NAME--------,USER--,DATE-----,TIME---,STATUS /Proj/abc/app/app_pit/conf/HUB_TEST.apx,uJones,4/24/...

My code in treat.awk is: #!/usr/bin/awk -f if($1 == "x") cat file And my input in command prompt is: ~/home/treat.awk x There appear an error message such: line 1: syntax error at or near if ...

Reference: The POSIX standard for the awk utility. One thing I really miss in awk is the ability to join an array with a delimiter, like with the join command in Perl, typically done for immediate ...

var="/ax1121/global/config/domains/adf_domain/config/fmwconfig/components/OHS/instances/vmserver1234/" I want the portion "/instances" to be removed and stored in a variable. After removal, it should ...

we have the following huge file 24G cd /var/log/zookeeper zookeeper-zookeeper-server-master03.sys645.com.out since this a log file , we want to remove all lines in file except the 1000 last line ...

I basically get the memory usage from two different nodes via ssh and store this in two different variables. I then select the host with lesser memory and return a code 0 or 1. The array arr contains ...

I am trying to extract the column name with the maximum value in each row using bash script i.e., the column header value or the value from the same column in the first row. I am using the following ...

Hi, I have two csv files: File1 (appx 18800 rows): p1 p10 p16 p19 p25 p3 p5 p6 p8 p9 A3 567 0 3 0 18 17 8 4 6 7 B23 490 7 6 2 23 26 20 14 ...

I am new to awk and I am trying to write an awk script which have string as a pattern and want to list all file in a directory which have this pattern in their name. but I don't know how to tell my ...

I have a file called session.log It contains some text data. 1st column contains serial number. 2nd column contains username. 3rd column contains last logged in date. 4th column contains result. One ...

I have a lot of files and need to merge strings among them by groups of three files. Each file has ~100-500 rows and the resulting file is ~100-200Mb. It seems like awk or sed can help me with paste, ...

I encountered a strange behavior (to me). I have written a larger script which is working well. When I try to start the script from a crontab-defined job, the following lines are causing issues: ...

i am trying to delete differnt values from a json file. Its not pretty and jq return 1 compile error". So i searching for a solution within bash (awk/sed). Here is my sample data from my json-file (...

$ stat -c "%Y#%n#%y" * | awk -F'#' "BEGIN {OFS=\"|\"} NR==1,NR==3 {print \$2 \$3}" directory1/Blum2017-12-22 22:33:38.644178442 -0500 dir2/Ciolli2017-12-22 21:53:51.769368496 -0500 Dar2017-12-06 13:...

Can anyone tell me how to use the awk command for this statement "the number will contain commas after every three digits. For example, 100000000 will become 100,000,000." I know how to use sed ...

I'm trying to match two files and print the match result and leave empty line for unmatch result, based on the Number column 3. The idea here to make the two file length the same . example: file 1 ...

How to insert bash variables in awk (for example i need to do in in some for loop - like this: in first iteration use awk to search string by first column, next by second column and so on with using ...

I am very confused about one simple script with awk: I want to print a range of rows by passing variables, the script below works: awk '{ if (NR >10 && NR < 100 ) print $0 }' file the ...

Here's a similar question but I ran into a problem that was not addressed in the question. How to replace the content of a specific column with awk? I want to do something similar, however my file is ...

I have data: 1528198031|Andr|thund|Lorem ipsum dolor sit amet, consectetur adipiscing elit 1528202225|Andr|thund|Lorem ipsum dolor sit amet, conse 1) Lorem ipsum dolor sit amet, consectetur ...

I have result file where I need to read the value of "rx cells " the report file is as given as below: Content of test.log file is as follows: co_result=test.log ZyXEL IES-1000> ...

File1: 23455|abc|xyz 23455|abc|xsd 34433|wer|sad 45655|fdf|fcd File2: v343v|23455 z565z|23455 c9898|34433 b2323|45655 Output should be: 23455|abc|xyz|v343v 23455|abc|xyz|z565z 23455|abc|xsd|v343v ...

I have a file that contains data something like: a 1 b 2 c,d,e 3,4,5 f 6 g,h 7,8 ... and I need the output like: a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 I can do this using python, but I want to try this ...

I have these two http://www.example.com:8888/index.php http://home.example.com:8888/index.php (home can be anything but www) and want to get this: example.com home.example.com Preferably in some ...

I'm trying to write a script to return duplicate values based on a set of parameters if they repeat twice. For example in my text file I have this setup: SPPARK|6543|M1122|6543|Hendrick|Brian|1977/...

I'm stuck on this script. I've defined a variable with a single cat of a temp file, and these are the following operations done by the script. PROJECT=$(cat temp/project_name_final) ; #...

I have a file looking like this chrom_pos chrom position BF window_id "Chr01__69500112" 1 69500112 10.1214802 "window_1391" "Chr01__69500129" 1 69500129 -7.59047205 "window_1391" "...

Here's what my file looks like: SRR008602 97 99 99 99 98 99 98 11 SRR009633 99 99 99 99 99 100 100 10 SRR022120 0 0 0 0 0 0 0 0 SRR026121 0 0 0 0 0 0 0 0 SRR008724 80 79 99 99 99 ...

So far I have my script (script.sh) as: #!/bin/bash/ BEGIN { print "Author Name of Book ISBN" print "------ ------------ ----" } { printf "%-9s &s\n", 1$, ...

I've a file like this, A1: abc.com B1: Hi there B1: Your Test mail A1: gml.com B1: Your new mail A1: hml.com A1: def.com B1: Test email B1: hello world A1: yml.com I want to always pick the A1: &...

we are trying to the delete the line that started with "content" word but without success "content" word actually can start in the begging of file or after spaces or TAB what is wrong in the sed ...

Input: 1,2,20,11 1,1,2018,111 Output: 1,02,20,11 1,01,18,111 i would like to insert 0 to field number 2 which is month in case if it's single number. And want to remove first 2 digits from field ...

I want to extract the logs between the current time stamp and 15 minutes before and sent an email to the people configured. I developed the below script but it's not working properly; can someone help ...

we have the following file: more test.txt export KAFKA_HEAP_OPTS="-Xmx8g -Xms8g" export KAFKA_JVM_PERFORMANCE_OPTS="-XX:MetaspaceSize=96m -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:...

Given an IPv4 address, is it possible to verify if the IP is in the range of a list of CIDR? For example, if I have the following CIDR, is there any way to check if 100.31.255.4 is in the range of ...

I have a file similar to this; where I want to remove every fourth line containing POPEL term and the lines not containing POPEL term should be unchanged. Is there any shell commands which I can use ...

Need to vlookup from two different files having duplicate entries: File 1 abc 10 xyz 20 bhy 30 hgf 40 File 2 a abc b xyz c bhy d abc e abc f ...

I have a list of data in a table. By using awk to pull out column 5, i was able to differentiate the data amongst the rows. If the entry at column 5 is more than 4, the row should be printed. ...

I need to replace a number using a script, I am using the following command for ((i=1; i=<10, i=i+1)) sed '244s/0.8/(0.$i)/' analyze3big.f >> $i.f But for some reason it does not work. ...

I use the following regex to find email addresses: echo "name@server.com" | awk '/^([a-zA-Z0-9_-.\+]+)@([a-zA-Z0-9_-.]+).([a-zA-Z]{2,5})$/ {print $0}' But it returns the error: awk: cmd. line:1: ...

Related tags

Hot questions

Language

Popular Tags