awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

1
vote
4answers
116 views

Bash: How to print additional column matching IP Address to Name

I'm using netstat to collect information about connected IP's. And I have the following format: netstat -tn 2>/dev/null | awk '/:80 / {print $5}' | sed 's/.*::ffff://' | sed 's/:.*//' | sor t | ...
1
vote
2answers
45 views

Search for processes which are CPU consumming

I can track the process launched by the user4 with awk: ps aux | awk '$1~/user4/' And also to track what process consume more than 10% CPU: ps aux | awk '$3> 10' Hoe the question is not too ...
3
votes
2answers
47 views

Sorting by two columns

I need help with this homework assignment: Write a shell script named sales1 using nawk and sort commands to do the following: 1. print the file in two sections, east and west, with lines alphabetized ...
2
votes
2answers
41 views

average of specific rows in a file and output in tab-delimited file

I have 6 rows in files. I need to find average only of specific rows in a file and the others should be left as they are. The average should be calculated for A1 and A2, B1 and B2, other lines should ...
1
vote
2answers
129 views

Find files containing a set of words

I'm using grep to find files within a directory, containing a set of words. But grep search lines containing these words, what I want is grep to show me the files or file containing all those words ...
1
vote
1answer
58 views

Extract random sample of N lines based on pattern

I have a file formatted like this: train/t/temple/east_asia/00000025.jpg 94 train/t/temple/east_asia/00000865.jpg 94 ... train/s/swamp/00000560.jpg 92 train/s/swamp/00000935.jpg 92 .... train/m/...
4
votes
4answers
146 views

Replace strings in a file based on a list of strings and a list of corresponding replacements

I am trying to replace strings in a file A: Hello Peter, how is your dad? where is mom? where the strings to be replaced are in file B: Peter dad mom and their corresponding replacements are in ...
0
votes
1answer
34 views

Remove tab, new line, carriage return until encountered char

I have a CSV file that has record separator of ,\n. One of the columns, has the possibility of containing tabs and new lines, which I wish to remove. How do I remove these chars (\t\n\r) using sed and/...
2
votes
0answers
58 views

Awk /sed extract information when a pattern match from a paragraph

I want to search a pattern "FROM" in paragraph that begins with CREATE VIEW and ends with ";" and save the result in a csv file. for example if I have the following file : CREATE VIEW view1 AS ...
0
votes
1answer
55 views

Monitoring Server Connections - Netstat formatting issue

I have had a few issues with a server recently. So i just wanted to leave a window showing the unique and IP's of connected devices. I have been using: watch -n 5 "netstat -tn 2>/dev/null | grep :...
0
votes
3answers
41 views

remove sequential lines that begins with the same pattern using awk or sed

I want to remove the sequential lines that begins with the same pattern "CREATE CURRENT" using sed or awk for example if have the folowwing file: CREATE CURRENT = 'aaaa' ; CREATE CURRENT = 'bbbb' ; ...
0
votes
1answer
43 views

subset a file just on one column

I have a tab delim file, I want to make a subset on the basis of column 2, choosing "A". 435 A 2 27.92464882 8.63E-07 1 752721 564 F 2 30.12532071 2.87E-07 1 798959 654 A 2 29....
0
votes
2answers
51 views

insert complex line before or after complex line

i have file with complex text print("ERROR: passwords don't match") password = hash_func(password.encode("UTF-8")).hexdigest() i need to insert this text between them with open('/etc/openvpn/...
1
vote
3answers
45 views

Count occurance of number and delete line of matches value

Could I get some help please with my problem? I have a file that looks like this (comma separated): A,250,13,820,0,80,201 B,0,0,0,0,3,0 C,0,2,1,0,0,0 D,0,1,105,0,0,10 I would like to ...
0
votes
2answers
221 views

How to output some data to different cells of an Excel File?

Example: I have a file that has following data: cvrta2100 Error 404 Fixed cvrta2111 Licensed Needs Fixing cvrta2123 Error 404 Fixed cvrta2333 Licensed Needs Fixing I am using awk to print ...
3
votes
2answers
71 views

match columns and replace

I am newbie in linux. I have two very large text files with space-delimited fields: File1 527858 51 2 27.92464882 8.63E-07 570289 82 2 30.12532071 2.87E-07 571034 90 2 ...
1
vote
3answers
76 views

How to do following formatting using sed or awk or bash script on linux

Suppose, I have two files: file1 having below contents. message_aaa.wav test 1 of 1 test Label : aaa test Sentence : test aaa test String: test message Interpretation ...
2
votes
2answers
55 views

AWK: How to put field ($1) inside regular expression to select all prefixes?

Assume I have a file A: fileA fileB Suppose I have now a file named: fileA_someprefix_20160101.txt Now I want to match all lines from A which prefix this filename, so I thought: FILE_NAME="...
0
votes
2answers
59 views

using awk to unzip files in directory

I have some zip files in directory when I need to unzip each in specific dir I used ls | awk '{ print "unzip " $1 " -d " $1} ' unzip p21286665_121020_Linux-x86-64.zip -d p21286665_121020_Linux-x86-...
0
votes
1answer
60 views

Merge files based on matching of first column

I have two files: File1 ARS-BFGL-BAC-10975 0.9303 688423261 1 01/04/2015 0.9983763305 ARS-BFGL-BAC-11025 0.9092 688423261 1 01/04/2015 0.9983763305 ARS-BFGL-BAC-11044 0.9626 688423261 2 01/04/2015 0....
-1
votes
1answer
50 views

how can i extract the second and third word of a line{that starts with 9} from a file where words are seperate with |? [closed]

case "$3" in -id) echo "Lines matches with the pattern $4 :" #grep -oP $4 $2 ;; esac
2
votes
1answer
84 views

I can't find the process sending mail?

I did something stupid and ran an awk that runs a while loop that sends an email every 10 seconds. I ran this as a background process: egrep '^[1-9]' /etc/hosts | grep -v 'localhost' | awk '{ system("...
4
votes
3answers
177 views

String replacement using a dictionary

What is a good way to do string replacements in a file using a dictionary with a lot of substituend-substituent pairs? And by a lot, I actually mean about 20 – not much, but many enough so that I want ...
-1
votes
1answer
38 views

Remove pattern from a line in file with Grep/sed/awk combo, pattern is another column

I have two columns (or could separate as two files) in a huge file and i need to remove the duplicate city name in the state/area column. los angeles los angeles ca, usa, west new york ...
0
votes
3answers
67 views

Awk command is not working properly

I have a very simple problem, but for reasons it does not work properly.. I have these .txt files in the following format 2 250 1 4 250 1 5 250 1 I wanted to subtract 1 from the ...
1
vote
1answer
32 views

Calculate hits within a timespan from log file [closed]

I need to use UNIX utilities that implement out-of-core divide-and-conquer algorithms so to decrease the amount of virtual memory used (cap of 1 mb). I have a large data set that is an apache log file....
3
votes
2answers
103 views

Passing a list of two PIDs to xargs only kills the first using ssh

I'm retrieving a list of two PIDs that I want to kill. My pipeline looks something like ps -ef | grep foo | grep -v grep | awk {'print $2'} | xargs kill -9 Both processes are killed when executing ...
4
votes
2answers
333 views

How do I print the (numerical) ASCII values of each character in a file?

How can I print the numerical ASCII values of each character in a text file. Like cat, but showing the ASCII values only... (hex or decimal is fine). Example output for a file containing the word ...
1
vote
3answers
73 views

Awk, print result

Why does awk '{print 3 + 3}' not work, but: echo 3|awk '{print $1 + 3}' does? Couldn't the first statement just output 6? What is the easiest way of printing the result of a calculation?
1
vote
2answers
54 views

Joining columns from files if they contain a match in another column

I have two files: File1.txt 30 40 A T match1 string1 45 65 G R match2 string2 50 78 C Y match3 string3 File2.txt match1 60 add1 50 add2 ...
0
votes
1answer
27 views

UNIX AWK : Get Logs from 24 Hours

I am trying to extract data from the log files for last 24 hours . I am trying awk -v d="$(date -d'24 hours ago' +'%Y-%m-%d %H:%M')" '$1" "$2>=d &&/ERROR/' data.log This does find ...
3
votes
1answer
74 views

How to optimize 'grep'-and-save?

I want to know on which node my calculations were running on our cluster in case the node crashes and I get no files back to know on which node I have to search. For that case I wrote a little script ...
11
votes
2answers
535 views

awk memory leak?

Base on this I'm running the command < /dev/urandom hexdump -v -e '/1 "%u\n"' | awk '{ split("0,2,4,5,7,9,11,12",a,","); for (i = 0; i < 1; i+= 0.0001) printf("%08X\n", 100*sin(...
1
vote
2answers
34 views

Reorganizing lines in a text file

So I have the following file: First Line Second Line Third Line 3 0.374 2 0.777 1 0.245 Fourth Line 4 0.687 ... And I want to reorganize it so the lines beginning with an int are appended to the ...
6
votes
1answer
140 views

Make bash exit != 0 when called by AWK and interrupted with ^C

I'm having an issue with the following piece of (G)AWK script: do { ... } while (system("sleep 10")) My intention is to break the loop when the user presses ^C during the sleep, but it's not ...
0
votes
1answer
36 views

Subset rows with awk [duplicate]

I am new to Linux, but my work requires me to do some specific task now, I hope you please help me for this. I have a data set as follow: Cow_ID Age DIM 1 1424 0 1 1425 1 1 1426 2 1 ...
0
votes
4answers
45 views

Change field separator in table

I have several tables having the following format 1971-01-01 1124 1971-01-02 987 1971-01-03 954 ... Instead I would like to change the field separator in order to have the following format of table ...
0
votes
2answers
31 views

placing words corresponding to a key in a singe row

I have a symbol table of the form (key-value pairs) 01 aaluu desii 01 aaluu cipsa 01 amaruuda ilaahabaadii 02 hai 02 nahii 02 txamaatxara To start with, I am supposed to place words(...
0
votes
1answer
61 views

Parsing text file using awk

I have a continuously changing text file that contains messages from the Gmail API. I need to parse the contents of it. My text file contains the id of the message, the message, sender details and the ...
1
vote
4answers
63 views

How to use printf with awk to designate the columns separated command output

I want to extract the manufacturer name, card's firmware version and status from the output of fcinfo hba-port, which looks like: root-#> fcinfo hba-port HBA Port WWN: 10000000c96a53c5 OS ...
2
votes
3answers
51 views

replace a string 6 line after matching string

I want to change notification_interval from 15 to 2 for block File_Check only. I tried changing line 6th after matching File_Check line with: sed -e '6 /File_Check/ s/15/2/g' file.txt but it did ...
2
votes
1answer
45 views

awk matching only 1 lines with same pattern

The following awk script will add an entry SAMPLE to block NOTES. I have multiple blocks with the same name. What needs to be changed in this command to add the entry SAMPLE to first block NOTES only? ...
1
vote
1answer
51 views

Multiline(in one paragraph) pattern replace use awk or sed

$cat test.txt blablabla ```{r} blabla ``` blablabla blablabla blablabla ```{r} blablabla blablabla imname <- "FIGNAME1" saveflag <- savepdf(imname) ``` ```{r} blablabla blablabla imname <...
1
vote
2answers
155 views

Replace column in one file with column from another using awk? [duplicate]

I have two files: file1.txt: 111|aaa|444 222|bbb|555 333|ccc|666 file2.txt: 111 (null) 333 replacing column two of file1 with column one of file2 Expected Output new: 111|111|444 222||555 ...
0
votes
0answers
106 views

Replace column in one file with column from another using awk? where column from another may have null values

I have two files: f1: 111|aaa|444 222|bbb|555 333|ccc|666 f2: 111 333 replacing column 2 of f1 with column 1 of f2 required output new: 111|111|444 222||555 333|333|666 I am using ...
1
vote
1answer
67 views

multi line awk regular expression [duplicate]

Consider text.txt with this content: blablabla &&&key word&&& I want all these text and numbers 123 and chars !"£$%& as output &&&key word&&& ...
0
votes
2answers
88 views

Awk run time error: not enough arguments passed

Here is the script: TYPE="${BLOCK_INSTANCE:-mem}" awk -v type=$TYPE ' /^MemTotal:/ { mem_total=$2 } /^MemFree:/ { mem_free=$2 } /^Buffers:/ { mem_free+=$2 } /^Cached:/ { mem_free+=$2 ...
1
vote
2answers
44 views

Can I access an array created in one awk script in a subsequent awk script?

I have a shell script where there are 2 awk strings. first_awk=' BEGIN { } { # create some array here.. } END{ } ' second_awk=' BEGIN { } { ## Access the array created in first awk section. } END{...
0
votes
1answer
55 views

Replace certain field from file with user input for each row and save in same file

Im typing to write a script which can read file_name, delimiter and field_number. After that for each row take an input, replace the field (specified by field_number) and output to same file. For ...
3
votes
4answers
163 views

Iterating through subdirectories and get two files as arguments for awk script

I need to iterate through the subdirectories of a directory and take two of the files, as arguments of an awk script. The script will compare the two files and generate other files. I've this. But I ...