AWK is a text-processing language. It is mainly used to manipulate and process structured data, and to generate reports.

learn more… | top users | synonyms

0
votes
1answer
11 views

awk - I can't print to file

I don't know ,why I can't print from to file. My command: awk 'BEGIN{print "af">file}' Error: fatal: expression for `>>' redirection has null string value
0
votes
2answers
27 views

AWK formatting Disk Utility command formatting incorrectly

I am trying to learn awk at the moment and so I am trying it on the disk utility command. Here is the output when I run Disk Utility list disk0 /dev/disk0 (internal, physical): #: ...
0
votes
1answer
11 views

Random function in awk like in bash

How can I random in awk. In bash is: echo $((RANDOM%(32-12+1)+12)) Is there function in awk, which gives the same result?
0
votes
0answers
15 views

awk - Assign variable result of system function

I would like to assign variable result of system function: awk 'BEGIN{x=system("cut -d \" \" -f 1 ol");print x}' Input "ol": 1 Result: 1 0
0
votes
2answers
37 views

Pass variable from awk to bash

How can I pass variable from awk to bash? I want to pass a lot of variable, so I don't use: x=$(awk '.....) I thing it's not usefull.
0
votes
2answers
22 views

AWK - Add variable and result of function to variable

I want to add variable and result of function in AWK. Input: t t t t a t a ta ata ta a a Script: { key="t" print gsub(key,"")#<-it's work b=b+gsub(key,"")#<- it's something wrong } END{ ...
0
votes
1answer
23 views

awk - awk concatenate string variable

I would like to awk concatenate string variable in awk. How can I do that? I tried: BEGIN{ t="." r=";" w=t+r print w} But I does't work. Output: 0 Or I want to add variable and result of ...
0
votes
0answers
9 views

awk print data in fixed column

I would like to print data in fixed column. I mean the column should be like in table. I used printf. Input: To find information use the search box on the top right corner of the screen, or ...
0
votes
2answers
36 views

awk and regex with {}

I want to print whole record if it contain word and some character, which are optional. Script: /mount[ein]{0,2}/{ print $0} Unfortunately it doesn't work. Without "{" and "}" it work. I tried with ...
0
votes
0answers
16 views

Counting keys in line awk

I have to check how many keys(3 last characters in word) is in the all lines, but awk sent error. I think awk don't correct check condition. I tested it changing key to "t(or somthing eles). My ...
1
vote
1answer
15 views

Display Associative array in awk

How can I display Associative array, when I don't know index? My script: { tab[$1]=tab[$1]+1 } END{ print tab[*]#display array -> it doesn't work }
0
votes
0answers
18 views

awk - field separator change in program, letters in the field

I want to change FS in awk, but not in BEGIN. I want to print word and the letter. awk 'BEGIN{FS=""}{print $1; FS=" ";print $1; FS=""}' Of course it does't work. Is there any function, way to show ...
0
votes
1answer
26 views

Why awk printing wrong string into the output file?

I'm trying to read file with awk and write the output in a new file. Content file sample: DATE_Login|09:01:20.507|2015-08-13|TIME_Session|00:32:32|MX|w32 ...
0
votes
2answers
22 views

How can I replace a newline with its escape sequence?

Using sed to make text that contains certain characters suitable for use in string literals is straightforward: sed "s/\\\\/\\\\\\\\/g" sed "s/\\\"/\\\\\\\"/g" But how can I do something similar ...
1
vote
2answers
22 views

Find duplicate column and separate them to a file or variable(Bash)

I have output like ; (The columns separated by tab \t) name1 something1 name1 something2 name1 something3 name2 something4 name2 something5 For this output I need two output (if there is ...
-1
votes
1answer
31 views

linux command to get quarter details

I need to paas current date to linux command which will give me output for quarter number I have two queries date +"%Yq$(expr $(expr $(date -d '-1 month' +%m) - 1) / 3 + 1)" result -> ...
1
vote
2answers
45 views

escaping awk with remote ssh command and bash that is already escaped

Hello. ssh ufk@10.0.0.2 "bash -lc 'pm2 list | grep app | awk { print $3} '" I need to run the command I pasted here. the problem is that i'm already escaping twice... the bash with " and the pm2 ...
0
votes
1answer
30 views

Pass a path with parenthesis and space in system call inside awk script

Inside my simple awk script, I call system command #!/bin/bash Test='/home/software/Other/new (Applet)' ls "${Test}" var=$(ls "${Test}") echo $var awk -vTest="$var" 'BEGIN { ...
0
votes
0answers
9 views

Mac OS X Find and Replace API

Are the Find and Replace operations under the Edit menu in Acrobat or Word simply a front end for the unix awk, sed or grep commands? Where can I find more information about what's going on underneath ...
1
vote
3answers
80 views

How to use grep or awk to save every line from text file as new file?

I am a scripting beginner. What i am trying to do. I have a text file that looks like this (example): hello hi there apple I am trying to make a script that saves every line as a separate new file ...
0
votes
1answer
46 views

need to get average idle time using mpstat

I want to get average idle time of the server using mpstat. The problem I am having is %idle is not in same columns in all the versions of linux. example 1: [root@testserver ~]# mpstat 1 2 Linux ...
0
votes
3answers
84 views

Match the column heading and print the values of the column using awk

I have a data in the file in columns. I want to write a script, which displays the data of the column matching the column heading. C-1 C-2 C-3 C-4 C-5 C-6 C-7 C-8 C-9 10 30 35 20 9 65 87 30 ...
0
votes
1answer
35 views

Monitoring changes in file with bash

I'm running DHCP server on local network which calls this script every few seconds: dumpleases | awk '{print $2}' > leasesnow #get list of all IPs leased in a file, one per line ADDED=`awk ...
2
votes
3answers
58 views

Extract version string from filename

We have a list of filenames in file a.txt with their version string embedded in them. Eg: gson-2.1 xmlParserAPIs-2.4.0 acrobat-1.1 orai18n-mapping-12.1.0.2 jdbc-se2.0 eclipse-core-runtime-20070801 ...
0
votes
1answer
68 views

Using ' (' (space followed by parenthesis) as field separator in awk

In an awk script I am trying to use ' (' as the field separator. However unless I escape the bracket with double back-slash, like this: BEGIN {FS=" \\("} it does not work. If I use FS=" \(" I get ...
0
votes
1answer
59 views

Script shell get id and kill process

Please, i can't find the error in my command. ssh -t root@$machine -x "sshpass -p 'ubuntu' ssh -t root@$address -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/nul -x 'ps -ef | grep ...
0
votes
2answers
59 views

Extending awk one-liner from identifying matching pair of columns (row by row), to multiple columns

I am using Win7 with Cygwin. I have a one-liner that will work for identifying matches in a PAIR of columns, but when I try to introduce additional columns (i.e. >2) I cannot get it to work. So the ...
1
vote
2answers
104 views

Best way to increment numbers in one line in Linux [closed]

I have one line with lot of entries among which is also time. ('DEFAULT',17,NULL,'2014-07-14 10:30:00','Something','2014-07-14 06:30:00',1),('DEFAULT',26,NULL,'2014-07-14 ...
2
votes
2answers
70 views

how to insert text at the beginning of each paragraph in bash

I have a file with multiple paragraphs separated by blank line. Technically they are not paragraphs just sections of text separated by blank line. I want to number the paragraphs so to speak by ...
1
vote
1answer
52 views

Multiple input files and output files in awk

I have a folder full of text files named 000.txt to 181.txt. How can I process all of them (on the command line) with the same awk script (program.awk) and send them to their respective output files ...
1
vote
1answer
53 views

How to parse a space delimited text file

I have a text file like this: Fam1000: CMIN|CMIN_9-RA CMIN|ABC_7-RA GCLA|EFX5.1 GCUC|GCUC_7-RA Fam1001: GCLA|EFX6.1 GCLA|EFX7.1 Fam1002: GCLA|EFX5.1 GCLA|EFX2.1 GCUC|GCUC_8-RA GCUC|GCUC_8-RA Fam1003: ...
0
votes
1answer
40 views

Skip the first 6 lines/rows in a text file with awk

How can I skip the first 6 lines/rows in a text file (input.txt) and process the rest with awk? The format of my awk script (program.awk) is: BEGIN { } { process here } END { } My text file ...
0
votes
2answers
78 views

How to copy file using awk based on time creation to some directory

I trying to copy a file to directory using awk filter based on time creation file #!/bin/bash dir=/home/resaputra23/pyexample/python2/* des=/home/resaputra23/pyexample/backup/ file1= stat $dir | awk ...
1
vote
2answers
86 views

Awk to merge two files using hash

I have two files of the same length, and I want to swap out one files 3 columns with another file's contents. I want to print the following: f1Col1 f1Col2 f1Col3 f1Col4 f1Col5 f1Col6 f2Col1 f2Col2 ...
1
vote
1answer
29 views

How to serach for a line which contains specific string in Bash?

I've got a file which contains some amount of lines, I want to look for a specific string, and if the file contains it, then I want to print a different line from the same file. for example, let's ...
0
votes
0answers
44 views

Multiple replace - using sed or awk

I have a code snippet like below CREATE TABLE TABLE1( ID integer NOT NULL, ROW_CREATED varchar (26) NULL, BATCH_LOG_ID integer NULL, TRANSACTION_TYPE varchar(5) NULL, PARTITION_COL integer ...
1
vote
1answer
22 views

SED/AWK/PERL(GNU userland) - how to substitute pattern A but not pattern B?

First, I am using GNU userland so you can assume I use Bash, GNU coreutils... I have a HTML and I want to change all href="foobarz" into href="" However, I don't want to change any line ...
0
votes
0answers
21 views

Strang, same simple awk script has different results on different machines

This is the strangest mystery ever -- same simple awk script has different results on different machines. The awk script is really simple: $ cat awk_test.awk BEGIN { troubleshoot = 1 } # GET: ...
0
votes
2answers
30 views

list file and using awk to get comment

I want to get the all comment of all files in a folder. And what I have tried is ls -R | awk '/<!--/,/-->/' >> result But it shows nothing in the result file. But if I use the awk ...
0
votes
1answer
56 views

Get the Group name which has GID=0

I wanted to write a shell script in which it needs to give the group name whose GID=0.I used awk command like this, awk -F ':' {$3==0} /etc/group | cut -d ':' -f1 It works fine in redhat,aix.But ...
1
vote
1answer
130 views

piping tail -f into sed or awk

There is another question which is nearly the same, but none of the suggestions from its answer works for me: Piping tail -f into awk I'm trying to tail -f a logfile but want to replace \r with \n ...
0
votes
2answers
31 views

quote-enclosed fields in input to awk

I'm trying to process a webserver logfile in awk. Like 123.222.333.444 - - [24/Feb/2015:13:09:19 +0100] "GET / HTTP/1.1" 200 15852 "https://www.google.dk/" "Mozilla/5.0 (Windows NT 6.1) ...." ...
0
votes
2answers
38 views

Sort on ID, then sort on date, then remove lines which have the older date?

I have a couple of tab delimited files. Each file is structured like so: ID Title Rating Date_Rated What I want to do is merge all these files into one, ...
1
vote
2answers
374 views

bash sed/awk: replace string from a file searching in another file

i have a question about search and replacement on Debian. I have two files. One with: a:b c:d e:f and the other with: e c a` In the second file I want to replace a with b, c with d, e with f. ...
0
votes
0answers
85 views

Copy huge file skipping first line using dd in Linux

I was trying to copy the content of a huge file (10GB) to another skipping the first line (as in head -n1). I tried multiple ways of head, tail, awk and sed. Settled on using tail -n+2 > ./xab.1 ...
0
votes
1answer
44 views

Replace with sed a tag value under a specific section when matching a line

I would like to change a line when another line matchs under a section of a file using the sed command (or awk). Here is an exemple of the file : Extract of MyFic.txt : <PlayList> ... ...
0
votes
3answers
72 views

using awk on only files which START with 'xyz'

I have 3 files in a directory: xyz1.txt, xyz2.txt, rst_xyz.txt and I want to work with ONLY the first two (those which start with xyz). The command ls | awk '/xyz/{print $1}' will return all three of ...
0
votes
2answers
129 views

Unable to get accurate record count of a csv file

I have a .csv file that has some values formatted as paragraphs with line breaks or sometimes bullet points. "STAT","ID","DESC" "UPD", "1", "Updated" "CHG", "2", "Changed" "UPD", "3", "Updated. ...
0
votes
1answer
26 views

How to fetch the string “Hi there” from the below array in unix

I only want to fetch Hi there and store it in a variable VAR1. So basically VAR1 should contain Hi there VIEW_COL[1]="Hi there,USA,Y" This is what i have tried so far. Column_Display_Name=`echo ...
0
votes
3answers
24 views

Filtering 2nd field from a data set and then using uniq on the output

I've got a dataset that goes like this: AAAAA 11111 Data1 AAAAA 11111 Data2 AAAAA 11111 Data3 AAAAA 11112 Data4 AAAAA 11112 Data5 AAAAA 11112 Data6 AAAAA 11112 Data7 AAAAA 11113 Data8 AAAAA 11114 ...