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

learn more… | top users | synonyms

1
vote
2answers
71 views

awk repeats lines too many times

I'm using awk to create a file that contains lines of text & uses an input file of numbers. i want to substitute each number in once, i.e. line 1 gets the first number, line 2 gets the second ...
-1
votes
2answers
47 views

substitute values in one text file into another text file

I want to use awk to create a text file that includes a series of awk text lines with numbers that are replaced in. problem i am having is that the text will include awk syntax. ultimately, i want to ...
0
votes
0answers
33 views

awk add certain colum if two columns are similar

First at all I apologize, but I am a newbie in scripting, and I try to learn something. I have a file which looks like this: 1 A 84.54 47355 1281 1 A 80.16 47355 761 1 A 81.63 ...
3
votes
2answers
62 views

tee results in a null file

I try to change Apache configuration with this: sudo awk '/<Directory \/var\/www\/>/,/AllowOverride None/{sub("None", "All",$0)}{print}' /etc/apache2/apache2.conf | sudo tee ...
0
votes
2answers
41 views

Extract numbers with awk

a part of a script in awk looks like this sub(/^Mutation: {"seq-pos":/,"") && sub(/, "time":/," ") && sub(/}$/,"") { print >"fifth_"FILENAME} The aim is that given this ...
2
votes
2answers
83 views

Search for number sequence

say you have a file1.csv containing 5 million lines, each line has 8 random numbers separated by comma. And you have this sequence 7,152,13,11,42,5,7 How to output the lines in file1.csv containing 3 ...
1
vote
2answers
29 views

roundign numbers perl [closed]

a vector I have looks like this v<-c(1,7,9,15,22,29,30,30,30,30,40,42,49,50,50,50,55) as I cant allow for numbers appearing more than a single time I would like to be the output like v ...
2
votes
2answers
102 views

How to merge values from two different text files?

I have following data set in text files: file1.txt a1:b1 a2:b2 a3:b3 a4:b4 a5:b5 file2.txt b2:c1 b4:c2 b5:c3 How to merge these values to make output file like this: output.txt a2:c1 a4:c2 ...
-1
votes
1answer
26 views

read numbers with e in awk

Hello a file I am working with looks: header // SeqT: {"POS-s":174.683, "time":0.0130084} SeqT: {"POS-s":431.49, "time":0.0221447} ...
1
vote
2answers
166 views

How can I divide an output with 2 delimiters?

By dividing with the "·" and " " characters, I would like to turn this: Hel·lo my name is E·ric To this: Hel·lo my name is E·ric Hel·lo my name is E· Hel·lo my name is Hel·lo my name Hel·lo my ...
0
votes
1answer
43 views

split files with specific pattern

A file I work with is like NAMES n0 n1 n2 n3 n4 n5 n6 n7 REGION chr 1 100000 404 AAAAAAGA 992 TTTTTTTA 1146 CCCCGGCC 1727 CCCCCACC 1778 GCCCCCCC My desired output is (please ...
1
vote
1answer
66 views

How to add command line options to perl script? [closed]

currently I have the following script #!/usr/bin/env perl use strict; use warnings; my %seen; my $header = <> . <>; print $header; my $last_sequence_number = 0; open( my $output, ...
1
vote
1answer
42 views

How to restrict the decimal places in awk without rounding off

I want to print 0.74 for 0.748. If I use awk '{printf "%0.2f\n",$1}' filename for 0.748 it prints 0.75. But I want 0.74 and remove remaining part. For 77.348 it should be 77.34. Any ideas? ...
0
votes
2answers
48 views

How to skip a record with awk

I have a large number of files in a log-directory, whose names were time-stamped (in this case with date +%b[...]). I want to write a POSIX compliant one-liner that will: either skip lines output ...
1
vote
7answers
551 views

Remove duplicated dots from file name

I have a dir with tons of files inside which have been named in malformed such as file..txt ,file2..txt ,etc... So how to easily remove this second . from file names? Any applicable method is ...
2
votes
4answers
76 views

Remove whitespace from all array elements

I have a array called arrayvar, which is being defined as arrayvar=( $(awk '/'"$vovar"'/,/}/ {gsub("'"$vovar"'"," "); gsub("}"," "); gsub("{"," ");gsub(","," ");print}' temp1 | tr -d '\n' | sed ...
2
votes
1answer
92 views

Passing Variable into awk gsub

I have this command Here vovar=OBJECTS prvar="$(awk '/'"$vovar"'/,/}/ {gsub("$vovar"," "); gsub("}",": %s,"); gsub("{"," ");gsub(",",": %s,");print}' temp1)" Contents of temp1 ...
1
vote
2answers
59 views

Make echo ignore spaces?

I have a file called temp1 sCellEventTrap-03-27 TRAP-TYPE -- CAC Code: 01 ENTERPRISE compaq VARIABLES { scellNameDateTime, scellSWComponent, ...
1
vote
1answer
68 views

diffrence between two files of different row numbers

Yesterday I asked this question, and got awesome answers, it's really a joy to ask questions on this site. Today I got a slightly different question say I have csv1 1,2,3,4 5,6,7,8 -- 9,10,11,12 ...
0
votes
4answers
52 views

Adding a number to a already present variable sed/grep/awk

I have this in file.txt FORM: lookupfile Version: 1 LookupFile:"$i" How can I find this in the file and add a variable b to the $i. So example INPUT FORM: ...
10
votes
5answers
752 views

Difference of two big files

I have "test1.csv" and it contains 200,400,600,800 100,300,500,700 50,25,125,310 and test2.csv and it contains 100,4,2,1,7 200,400,600,800 21,22,23,24,25 50,25,125,310 50,25,700,5 now diff ...
1
vote
3answers
120 views

retain white spaces in fields when using awk

I am using nawk on a pipe delimited file to print fields as index and key where some of the fields contain white space, when there is no white space everything works normal, but in case of white ...
-2
votes
4answers
69 views

Copy a string occurring before a particular pattern.

I am to copy this emuEventTrapInformative from below. -- Traps emuEventTrapInformative TRAP-TYPE ENTERPRISE compaq VARIABLES { scellNameDateTime, shelfId, ...
0
votes
3answers
56 views

Print a string a number of times [closed]

I have a variable numvar which contains a number. CODE something that reads number stored in numvar and then creates the same number of sTrapValue[with a number here that incrementally ...
-2
votes
2answers
72 views

Delete lines between 2 strings

I am to delete all stings from starting of file to a certain point using anything, sed, Grep, awk in shell INPUT sCSISmart20 TRAP-TYPE ENTERPRISE cyclone ...
2
votes
5answers
123 views

Condition that matches all occurrences of a word in a file ad does something

I am to do something like this for (( every occurrence of the word TRAP-TYPE in a file )) do desc="$(< inputfile awk '/DESCRIPTION/ {getline; gsub(/^\s*"/, ""); gsub(/"\s*$/, ""); print}')" ...
3
votes
5answers
281 views

sed remove last 2 numerals

I have the following. oid=.1.3.6.1.4.1.795.2.5.0.xxx (these 0.xxx represent any random numeral) I want to do the following echo $oid | sed (some commands to remove 0.xxx) and store the resulting ...
2
votes
3answers
230 views

How to delete lines starting with certain strings

Is there a way to delete lines starting with certain strings. I have this youtube-dl code youtube-dl --extract-audio --audio-quality 0 --newline --audio-format mp3 ...
3
votes
1answer
210 views

youtube-dl file download progress with zenity progress bar

How to add youtube-dl file download progress percentage to zenity progress bar sample code (just an example, not a working one) #!/bin/sh ( progress=$(youtube-dl --extract-audio --audio-quality 0 ...
0
votes
0answers
57 views

awk-gawk link problem

I was trying to run some scripts of a particular code[FLUKA-CERN] through UBUNTU-14.04 . And I got the [[: not found error while running it. Then the code experts suggested me to install GAWK and set ...
2
votes
5answers
596 views

Command not found error awk

I am getting this command not found error in this code. I want to print first word of a sentence First code (result needed= 1) abc="1 hello world"; L=$($abc|awk '{print $1}'); echo $L 1: command not ...
0
votes
1answer
67 views

Fetching details using awk in zenity list

I am using youtube-dl to fetch videos and its format. this is my code youtube-dl -F https://www.youtube.com/watch?v=uvr1xiEaICU |awk 'NR > 5 { print}' | zenity --list --column "youtube" And ...
5
votes
4answers
103 views

Specific edits to a text file (awk?)

I have a file that looks like TITLE 1.000000000000000 10.0000000000000000 0.0000000000000000 0.0000000000000000 0.0000000000000000 10.0000000000000000 0.0000000000000000 ...
3
votes
2answers
334 views

Get specific PID and save to file

I'm running two minecraft servers on my machine. I want to know what the pid is of a single mc server that is running and put it to file so that I can kill it later. So for this example I only want to ...
-3
votes
1answer
37 views

Which is the most efficient search and replace tool? [closed]

Asking out of curiosity, which is the most efficient/fast "Search & Replace" text tool? awk or sed or any other?
2
votes
6answers
261 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 ...
1
vote
1answer
51 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
138 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
146 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
61 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
56 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
49 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
116 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. ...
18
votes
5answers
475 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
599 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
414 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
246 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
73 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
68 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
305 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) ...