awk is a special-purpose, interpreted programming language for extracting and reporting data.

learn more… | top users | synonyms

2
votes
6answers
173 views

How can I extract text between a pair of the same character?

Input: blahŤfoobar1Ťblah Desired output: foobar1 I want to get the text between two "Ť" characters. Assume there will always be either 0 or 2 "Ť" characters, to make things easier. I tried the ...
-2
votes
0answers
24 views

I Need execute a awk sentence on windows server [closed]

I Need execute a awk sentence on Windows Server, this sentence, read a file.txt, field takes column 4, and prints, I need run this sentence. thanks. Sentence:awk '/"Box11"/ { print $0 }' test.txt|awk ...
1
vote
0answers
23 views

How to pass the line number, where the mismatch occurred in awk, to Shell variables?

I am trying to compare two csv files. I want the line numbers to be stored into shell variables or array. I tried something like this: paste <(awk -F, '{print NR,$1}' file1) <(awk -F, ...
3
votes
2answers
90 views

Recursively rename files [duplicate]

there is a whole bunch of files all of them who have the pattern joob_1_1 joob_1_2 joob_2_1 joob_2_5 so it is joob then underscore numeric underscore numeric - these are also the only files in the ...
2
votes
1answer
49 views

Using awk command in perl script [closed]

Can somebody suggest how to use piping of commands in a perl script? Specifically commands that involve calling awk? I'm trying to create a perl script that will read disk usage using df -H and ...
-1
votes
2answers
42 views

How do I print all the usernames that have same UID in `/etc/passwd` by using awk?

How do I print all the usernames that have same UID in /etc/passwd? This is my command $ awk -F: '{print $3, $1}' us.txt | sort 0 daemon 0 pepe 0 root 2 bin 2 jacinto 3 paco
3
votes
2answers
45 views

Automatically doubling the value of numbers in a string in multiple files

I'm trying to modify Java source code in numerous .java files that contain strings similar to this: private static final Height biomeHeight = new Height(0.1F, 0.2F); There are over 75 and I'd like ...
2
votes
2answers
38 views

How can I put a cluster lines in numeric order?

How can I convert this: -foo -bar 42 \ randomtext=00 "00" \ -randomtext=00 "00" \ -foo -bar 104 \ randomtext=00 "00" \ -foo -bar 1 \ -randomtext=00 "00" \ To this: ...
3
votes
1answer
40 views

Parsing output of lsof or lshw to awk

I've noticed that lshw and lsof both take minute to load its output, and if I pipe their output to be processed by awk, I get the help message from awk and then . . . nothing from the first command. ...
5
votes
8answers
508 views

How can I delete text that is NOT in quotes or parentheses?

Input: 19. "foo foo" (bar bar) (19) raboof "foo foo" raboof Expected output: "foo foo" (bar bar) (19) "foo foo" As you can see, I would like to keep the double quotes and parentheses. ...
17
votes
5answers
375 views

How can I merge files on a line by line basis?

cat file1 foo ice two cat file2 bar cream hundred Desired output: foobar icecream twohundred I already have a solution involving a for loop with sed using the line number of the files, but in ...
4
votes
4answers
210 views

How can I extract text between parentheses containing a specific word?

How can I convert this: foo (blah) (bar 80) foo (cats) (blat 92) To this: foo bar 80 foo blat 92 I would like to keep all the text that is NOT in parentheses. I only want to extract text ...
6
votes
5answers
294 views

How can I edit a range of text between 2 symbols? awk, sed, regex

Using the "*" symbol, (doesn't have to be that one, any special character will do in order to indicate), how can I edit the text from this: *berry straw rasp blue boysen * blahblah blahblah blahblah ...
4
votes
3answers
215 views

How to use double substitution in awk?

To print the fields at 29th column in two files I used paste <(awk -F, '{print $29}' PreRefFile.csv) <(awk -F, '{print $29}' Txlog.csv) This worked fine. To print all the fields starting from ...
0
votes
1answer
28 views

How to compare float variables in awk?

awk -F, 'NR==FNR{c[$29]=$29;next} NF{print $29 ((c[$29]==$29)?" ":",mismatch")}' $file1 $file2 The value of 29th field, i.e., $29 in file1 was 832.9 and that of file2 was 832.9000. If I compare them ...
0
votes
2answers
39 views

How do I write an awk script that catch ping's time in seconds?

How can I make ping show ms and time in (seconds)? I found this script: $ ping google.com | awk 'BEGIN {FS="[=]|[ ]"} {print $11}' 16.8 16.8 15.7 18.8 How do I write an awk script which brings out ...
3
votes
4answers
257 views

What is a practical way to list every character used in a file (Bash) (Regex)

How can I turn this: Johnny's penguin, (Tuxie), likes the following foods: French fries, and beef. To this: abcdefghiklnoprstuwFJT',():. (These are the total characters used in the input) ...
0
votes
1answer
62 views

How can I split a line in 2 by words/characters? (Bash) (Regex)

I would like to convert: Hello Hello Hi Hello Hello Hi Hi Hi Hi Hello To: Hello Hello Hi Hello Hello Hi Hi Hi Hi Hello I want to split a single line in 2, by having them have the closest amount ...
2
votes
1answer
35 views

Join two files keeping the element order of one of them

I have two files File1 03873 03872 03871 03870 ...... File2 00001 0.867 00002 0.855 00003 0.864 00004 0.855 ... 03870 0.825 03871 0.852 03872 0.326 03873 0.852 I want to ...
3
votes
4answers
79 views

Find and replacement of the numerical part of a particular string with increased value using terminal command [duplicate]

The inputfile is, test00.dat test07.dat test03.dat aram22.dat test09.dat aram09.dat test13.dat I need the output file as test01.dat test08.dat test04.dat aram22.dat test10.dat aram09.dat ...
3
votes
3answers
203 views

How to label occurences of text?

I would like to convert blue blue red green to: color.1=blue color.2=blue color.3=red color.4=green Any leads on how to tackle this? sed, awk, etc.?
0
votes
1answer
70 views

awk print output redirection

I am writing a bash script, and in that bash script I have a line similar to this: awk '/TextToBeMatched/ { print; print "TextToInsert"; next }1' "/Path/to/specified/file.extension" And currently ...
0
votes
3answers
52 views

Substitute specific char sequence inside filenames

A friend of mine grouped tons of files in this way on windows After I made him switch to Ubuntu, files are no more ordered based on the number of exclamation marks in front, so I would like to know ...
4
votes
2answers
101 views

Print a group of lines if they contain specific strings

I have a file (file 1) that looks like that: >C 0 0 4231aa, >A6_03412... at 1:4226:1:4240/95.44% 1 4240aa, >A5_01600... * >C 1 0 4159aa, >FG1_03697... * >C 2 0 3942aa, ...
2
votes
4answers
269 views

Repeat each line in a text n times

I have a file that looks like this 888 924 873 1374 ..... The dots indicate that I have many more string, around 3000. I want repeat each string n time, to have something like this; 888 888 888 ...
2
votes
2answers
39 views

awk: matching strings to decimal values and summing them

I have strings that are supposed to match with numbers. For example, one is equal to 1 Now, I have a file that separates columns with ; and I want to write an awk expression that checks if the SUM ...
2
votes
4answers
242 views

count the number of unique values based on two columns in a spreadsheet

I need to count the number of unique values based on two columns in a spreadsheet. Suppose the file looks like this, ordered by name, surname, company: joe allen ibm joe smith ibm joe allen google ...
0
votes
1answer
142 views

Printing from arrays vs awk 'NR

I am currently printing out values from vmstat stress tests using this: vmstat -a $INT $CNT | awk 'NR > 1 {print $13,$14,$15}'> vm.log_$D & sleep 5 && stress --vm $cores -t ...
0
votes
1answer
55 views

How to find and replace a particular string by increasing its numerical part? [duplicate]

My input file is, ami41 ami56 ami23 ami67 ami45 ami34 ami88 jama66 tumi234 bichi23455 susami345 Using a single command line I need the output as, ami42 ami57 ami24 ami68 ami46 ami35 ami89 jama66 ...
0
votes
1answer
35 views

grep single pattern having more than one matches

I have a file (X.txt) with a list of unique entries. I would like to use this file to grep from another File Y.txt which contain more than one entries for single pattern of X.txt. X.txt contains: ...
3
votes
3answers
251 views

How to find and replace a string by increasing its numerical part?

My input file is, ami21 ami65 ami67 ami66 ami88 ami76 ami29 ami55 ami54 ami32 Using a single command line I need the output as, ami22 ami66 ami68 ami67 ami89 ami77 ami30 ami56 ami55 ami33 I ...
-2
votes
2answers
71 views

AWK is not printing the result

I want to write a simple awk command in Ubuntu (version 14.04), but it is not returning anything. $ cat sample.csv 001,Text1,Val1 002,Text2,Val2 003,Text3,Val3 $ cat sample.csv|awk -F',''{for ...
1
vote
2answers
134 views

Grep strings in a subgroup of lines in txt file

I have a file that looks like this AAA_21 PF13304.1 x_00004 AAA_22 PF13401.1 x_00004 SMC_N PF02463.14 x_00004 AAA_29 PF13555.1 x_00004 ...
1
vote
1answer
31 views

Awk variable passing question

This is the code I wrote to resolve DNSs and output to a file. Is there a way to forgo the while loop entirely and just write in awk? It works perfectly but it seems very cumbersome and inefficient, ...
2
votes
1answer
934 views

bash comparing multiple column in two files with different length

I have following data set in text file data.txt d1,40,gold d2,30,silver d3,20,bronze d4,10,iron d5,5,wood d6,20,gold d7,10,wood d8,5,gold d9,10,silver . . . def.txt gold,40 silver,30 bronze,20 ...
2
votes
2answers
123 views

bash text colon values to html table

i had a big file with more than 10000 recordslike below, this need to be converted to html table i tried various ways with converting into csv and then to html etc.., not able to get the desired ...
1
vote
2answers
90 views

How to print both matching lines from two different files? [duplicate]

I have file1 and file2 as following. I would like to first find matches between two files based on first column and then print the matching lines from file1 and file2. I have written the desired ...
0
votes
2answers
28 views

Extracting latest googleAppEngine with curl + awk

I am trying to extract the latest version of google app engine from their catalog. To do this I am using curl + awk. I found that the following regex extracts what I need: ...
0
votes
1answer
62 views

stripping a string using awk

input string prashant@prashant:~/Desktop$ xyz /123/ {print } abc.txt after using awk command to strip on above input string I should get below output string xyz /123/ {print } abc.txt
1
vote
1answer
315 views

cat vs grep vs awk command get the file content which one is more efficient and less time consuming?

Lets say I have file content like this: this is a simple file for testing purpose with few lines in it. to check the cat and grep command to verfy which is best and less excution time consuming ...
5
votes
1answer
365 views

Choosing awk version on Ubuntu 14.04

I am using Ubuntu 14.04, and making heavy use of all the great commands awk, sed, sort and so on. Recently it came to my attention that Ubuntu uses mawk as the default implementation, but since I ...
-1
votes
1answer
81 views

Making use of awk on string [closed]

I'm interested in listing in the terminal the lines from a csv file where the first character is 'A' . Is there a prompt way to do that?
1
vote
1answer
47 views

What is the purpose of '/' in awk command?

Why does this works : echo 'NetRange:192.168.1.1-192.168.255.255' | awk -F: '/NetRange/ {print $2}' and this doesn't echo 'NetRange:192.168.1.1-192.168.255.255' | awk -F: 'NetRange {print $2}' ...
1
vote
2answers
51 views

How does awk -F work?

Can you please explain as to how the followin piece of code works? l_Basename="hello_world.ksh" l_THIS_FILE=`echo $l_Basename | awk -F. '{field=1 while (field < NF) { ...
3
votes
6answers
784 views

rename multiple files with delimiters

How could I rename multiple files like, IonXpress_049.T11014.R_2014_11_13_11_26_35_user_PR2-41-Pooling0026_3140_13112014.bam ...
4
votes
4answers
1k views

How to find all patterns between two characters?

I'm trying to find all patterns between a pair of double quotes. Let say I have a file with contents look like as following: first matched is "One". the second is here"Two " and here are in second ...
2
votes
2answers
136 views

awk command while ((getline < “gpsoutput.tr”) > 0 for constantly updating file contents

I am currently using a G-STAR IV globalsat GPS which gives me the following output (which is coming from the GPS every 1 second) and I save this output by redirecting to a file name "gpsoutput.tr". ...
1
vote
3answers
96 views

csv file adding and removing characters from rows [closed]

I have a big csv full that looks like so else if(a,b,c,d,e) else if(a,b,c,d,f) I want to make it look like so else if(a+x==b and b+x==c and c+x==d and d+x==e) else if(a+x==b and b+x==c and c+x==d ...
1
vote
1answer
100 views

why my bash script only outputs one line on echoing awk variable

Anyone can probably tell I'm new at scripting and have tried doing as much homewaork before posting here. I have what I think is a simple script parsing out DNS zone file for IP and unique domain ...
0
votes
2answers
65 views

AWK counting back

I have a list of domains matched and piped in through grep with various length but all match the last three records. I'm trying to output all of the non-qualified sub-domains. I have: awk -F'.' -v ...