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

1
vote
1answer
15 views

I have file called songs and i'm trying to find the longest and shortest song name using AWK

RANK NAME BAND YEAR GENERE DOMESTIC/INTERNATIONAL 206:Reach Out, I'll Be There:The Four Tops:1978:Pop:3/2 207:Bye Bye Love:The Everly Brothers:1950:Classic:3/2 ...
0
votes
1answer
35 views

Piping tail -f into awk

Greeting, I am trying to pipe tail -f into awk to monitor a logfile in realtime, but according to examples, there should be not problem but I can't get it to work. here is the command I'm running ...
0
votes
0answers
14 views

stdbuf not working while unbuffer does

I am trying to apply timestamps to stdout of a process. For the proper timestamps to be applied, I attempt to unbuffer stdout of the process. This works with unbuffer but not with stdbuf as I would ...
2
votes
1answer
22 views

Weird behavior of awk

Why do I get only "cat" when I run awk 'BEGIN { animal[three] = "hen" animal[two] = "dog" animal[one] = "cat" for (var in animal) { print animal[var] } } ?? Shouldn't it print ...
0
votes
0answers
22 views

awk remove sign “,” in all columns, if it exists between

My data input file: 508,186,,Name,"VIA PAS, 4",vou1@mail.com, 291,345,,Name2,Votros 73,vou2@mail.com, 911,733,,Name3,zap 101,vou4@mail.com, 9000,32,,Michel,hops 12,"x1@mail.com, vou7@mail.com, ...
0
votes
1answer
39 views

How to find the matching records from 2 files in unix

I have two files which contains email_ids. 1. Test1.txt 2. Test2.txt Test1.txt contents are: abc@gmail.com xyz@gmail.com mns@gmail.com Test2.txt Contents are: jpg@gmail.com joy@yahoo.com ...
0
votes
0answers
6 views

Grep values from nethog and netperf [duplicate]

I need to monitor the network activities of a process and the bandwidth of the connection. So I decided to use nethog and netperf combine with grep and awk to write the values to a file. nethog ...
0
votes
2answers
45 views

Grep values from nethog and netperf

I need to monitor the network activities of a process and the bandwidth of the connection. So I decided to use nethog and netperf combine with grep and awk to write the values to a file. nethog ...
1
vote
2answers
46 views

moving directories after grep

I have isseued the next command in order to move some directories to the "build_tools" folder however the result was not the one I expected. ls -l | grep 2014-03 | awk '{if ($8!=build_tools) print ...
-2
votes
1answer
38 views

awk to print the line number of a closing bracket

I have a file 1.txt ejryheiur rewurie ( ejwhrejkrh rewrhwe rewkhrwe rewhkr ) dfhgsdfh rqwergjweg jhwgrh ( rehgwrwhe rhwejkr ) With this nawk script nawk ' BEGIN { ...
0
votes
2answers
53 views

Replace string in string but not when its somewhere between double square bracket

I have a long string from mysql field containing the data of a mediawiki page. I have to replace a string in that mediawiki page but not when the string is in mediawiki link. The mediawiki link is ...
0
votes
2answers
59 views

Replace words on given line numbers

I have a file 1.txt INTEGER-d_int () INTEGER-d_int () INTEGER-d_int ( ) INTEGER-d_intClass() INTEGER-d_intClass new() and I want to replace the occurrence of d_int with d_INT on the ...
0
votes
1answer
33 views

How to encrypt the mail in unix?

I want to encrypt the mail as that will be containing the confidential information. There are no attachments. Please help in providing the steps to encrypt the mail. I have got the reference of How ...
0
votes
1answer
58 views

How to replace an exact matching word using gsub

Please see the below script - On this nawk 'NR==FNR { a[$1]=$2 ; next} {for ( i in a) gsub(i,a[i])}1' file.dat 1.txt 1.txt ioiufeioru dfoiduf MO_CIF_INP438 fjkdj MO_CIF_INP dsjhdf BP_LINKED_TETES ...
3
votes
2answers
124 views

How to comment out multiple line matching a regex using sed or awk

I have a file that contains this: [...] location /static { ... multiple lines ... } [...] location /static/ { ... multiple lines ... } [...] And I want to get: [...] # ...
1
vote
2answers
48 views

Is there a way to print 2 lines (if any) before and after a target or print a placeholder if not?

I'm not native english speaker so I hope to be clear. I know about grep -C 2 "TARGET" inputfile to select 2 rows before and after the row of the TARGET, but I'm not able to use it to manage my ...
0
votes
2answers
28 views

grep out condition and add the values of the grep value

I have a scenario that a csv file has the values of : abcd FAILURE 7 abcd SUCCESS 12 efgh SUCCESS 3 efgh FAILURE 5 mnop SUCCESS 6 mnop SUCCESS 4 abcd FAILURE 5 efgh SUCCESS 2 mnop SUCCESS 1 ...
2
votes
1answer
56 views

grep the string lines from the file

csv file. 1,2,3,abc 2,3,4,def 3,4,5,abc 3,4,2,def 6,7,9,abc. I need to read that file and get the lines of file containing abc.
-1
votes
2answers
50 views

how to find number of substrings between delimiter? [closed]

I have the string following something(1)^^^something(2)^^^something(3)^^^ ... ^^^something(n) how to find number of something(s) in the string.
1
vote
1answer
189 views

Extract the contents of ELF and write to binary file

I have been trying to extract the contents of a firmware and putting it to a binary file, but with no success. I see the right hex contents, but am not sure how to laid them in bits into a file. ...
1
vote
2answers
124 views

batch find/replace using sed or awk

In every file with filename matching pattern1 I want to search for lines which start with pattern2, and add some string in a new line above those matched lines. As a simple example suppose I'm ...
1
vote
4answers
177 views

How to split CSV files as per number of rows specified?

I've CSV file (around 10,000 rows ; each row having 300 columns) stored on LINUX server. I want to break this CSV file into 500 CSV files of 20 records each. (Each having same CSV header as present in ...
0
votes
1answer
145 views

Suppress awk warnings

On a script, I get some warning of the form awk: warning: escape sequence \( treated as plain (. Since I want to use the output of that script to do stuff, I want it to output only results and not ...
0
votes
2answers
235 views

using awk with find -exec

I have a directory structure with 14 directories containing a bunch of files containing data in a three-column format (separated with tabs). I intended to use find and awk to extract the second column ...
2
votes
4answers
477 views

Print line X lines before/after found line

I want to search for a particular string in a certain file. If I found the string, I also want to print the line X lines before (or after) that line. Can this with grep or awk, or do I need a ...
1
vote
1answer
81 views

printing only first finded match

I've created a statement which is searching for specific informations in each line (in my case "AAA","BBB" or "CCC"), if there is no such information N/A is printed { k=0; for (i=1;i<=NF;i++) ...
1
vote
1answer
23 views

awk is limited to only one line operations?

Like in the subject. Let say I have a file which contains: *aaa A B C D E F 55 *ccc A B C R E T 33 and I would know if it's possibe to make a statement if $1=="*aaa" then print $4 ...
0
votes
1answer
85 views

Find number in string and replace it

I wrote C++ code and now I want to replace the number in a string by using shell scripts. The part that needs to be replaced: if (random<=90) How I can change the 90 from a shell script? I ...
1
vote
1answer
36 views

AWK does not work correctly in my system [duplicate]

i cant run this code because of an error awk 'BEGIN {x=0;y=0} { match($13,/([0-9]+)/,a); x = x + a[1]; match($12,/([0-9]+)/,b); y = y + b[1]} END {print "rxPackets:" x " txPackets:" y}' yourfile ...
0
votes
2answers
59 views

sum numbers in different lines in shell

i have 8000 lines similar to this <Flow flowId="1" timeFirstTxPacket="+0.0ns" timeFirstRxPacket="+924100.0ns" timeLastTxPacket="+199984927558.0ns" timeLastRxPacket="+199675473275.0ns" ...
-1
votes
3answers
93 views

convert text file column field with data dd.mm.yy to dd.mm.YYYY

How to format date for file content using linux command line tools? Input: aaa;1.70;ccc;20.01.13;zz;2013; uuu;2.70;lll;17.12.10;zz;2013; fff;3.70;nnn;31.01.98;zz;2013; auu;8.70;nuu;30.02.96;zz;2013; ...
1
vote
1answer
23 views

`nawk` “doesn't work” with `make`? Why?

I have the following alias: alias mca_color='nawk '"'"'BEGIN { arr["Creating shared object"] = "1;31";} \ { l = $0; for (pattern in arr) \ { gsub(".*" pattern ".*", "\033[" arr[pattern] ...
2
votes
2answers
46 views

Use tail directly on website data, or another utility needed?

I am planning to extract a single field of data from the last line of data on a website to populate an RRD database. I'm running Linux. The website is: ...
1
vote
1answer
35 views

Precising if statement in awk

Is that possible to precise conditions in "if" statement? Let's take an example from my previous post (by the way, "k" variable is tricky, thanks terdon;)) and say that I'm looking for $i which starts ...
0
votes
2answers
58 views

combining loop “for” with statement “if”

I've created a script for awk. I'm combining loop "for" with "if" statement. It's searching each line for word "ABC" which can occure in different place in the line. It looks like below: {for ...
0
votes
0answers
33 views

several awk commands consecutively

I'm using awk command to extract some datas. The point is that I need to use awk command several times to extract all informations I need and each time when I'm using awk I need create a temp file. My ...
0
votes
1answer
48 views

combining bourne shell and awk

This is my actual file WASfile #!/bin/sh sed -i '/^ *$/d' WASfile sed -i -e '/user=/,/group_1=/{w /tmp/1' -e 'd}' /home/wasdm/WASfile; Script to Add read -p "Press [Enter] to continue for ...
0
votes
1answer
78 views

match patterns update output file uncomment when desired

Need suggestion for following. Have two files myfile and responsefile. First file myfile.txt user=myname user_1=yourname group=mygroup group_1=yourgroup second file responsefile.txt ...
0
votes
2answers
83 views

split a textfile after each n matches to a new file using sed or awk

i tried to split a file in parts of n matches each. The file is just one line and the seperator is '<br>' foo<br>bar<br>.....<br> I just want to split the file in parts, ...
0
votes
1answer
45 views

Why is this awk statement not working?

awk 'BEGIN { COLM_FMT = "%-8s, %-8s, %-8s, %-8s, %-8s, %-8s, %-8s, %-8s, %-8s, %-8s, %-8s, %-8s, %-8s, %-8s,\n" } { printf COLM_FMT, ${totals[0]}, ${totals[1]}, ${totals[2]}, ...
0
votes
1answer
41 views

Move numbers in a filename to the start

I have several files in a folder, with names in the form: SOMETEXT1 number SOMETEXT2.mp3, or SOMETEXT number.mp3. I want to rename these to number SOMETEXT SOMETEXT2.mp3, or number SOMETEXT.mp3. Using ...
0
votes
3answers
323 views

Unix - Surround First Column of CSV with double quotes

I have data in the following format - 4,"abc" 8,"def" 9,"ghi" I want to surround the value of the first column by double quotes. "4","abc" "8","def" "9","ghi" How do I do that ?
0
votes
2answers
30 views

Count the number of lines in a piped input?

While running ps -eaf I see a list of running processes. Is it possible to count the number to lines using awk?
1
vote
0answers
33 views

Automatically Split a Huge TeX File Into Many Smaller Files

How would I automatically split the sections or chapters of a huge TeX file into many smaller TeX files? This somewhat works: awk -v RS='\\chapter{' '{print "\\chapter{"$0 > (NR".tex")}' ...
0
votes
4answers
103 views

Changing multiple lines in to single line with spaces in linux

I have following data with multiple lines username: joe empid: 1111 status: resigned username: tom emid: 1234 username: kate empid: 2222 status: resigned What I want is to get the data in to ...
2
votes
1answer
370 views

Round off the decimal value in awk

i want to round off the value 262.5 to 263 using awk i have tried the below echo "262.5" | awk '{printf "%.f\n", $1}' My expected answer is 263
1
vote
2answers
320 views

Sum a particular column and take the unique record of another using AWK only

I have an input file like the following: 19 | 17 | 1 | 89 | C | 9 | 100 | 9 | PL | 2175 20 | 17 | 1 | 89 | C | 9 | 100 | 9 | PL | 2175 21 | 17 | 2 | 89 | C | 9 | 100 | 9 | PL | 2175 23 | 17 | 2 | 89 ...
1
vote
3answers
1k views

How to get video duration in seconds?

How can I get video duration in seconds? What I've tried: ffmpeg -i file.flv 2>&1 | grep "Duration" Duration: 00:39:43.08, start: 0.040000, bitrate: 386 kb/s mediainfo file.flv | grep ...
-1
votes
1answer
186 views

How can I find my awk version?

If I want to know the version of awk I get the following: $ awk --version awk: not an option: --version Checking in man awk I see that my awk is mawk - pattern scanning and text processing ...
1
vote
2answers
115 views

How can I sort and de-dupe a very long list of words?

I have a 400 megabyte file. The file is a list of words, each word on a single line. End of lines are a mix of cr/lf and lf. Some of the words are unicode. I'd prefer answers for Linux or Windows ...