awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

-1
votes
2answers
55 views

Sorting multiple line columns

In the text: 35 EAST 23rd Street SOUTH AFRICA 5 600 5000000 6 83 NORTH YELLOWLIGHT AVENUE SOUTH AFRICA 4 700 7000000 5 777 NEW AVENUE SAUDIA ...
1
vote
1answer
172 views

I am trying to fetch the logs for last five minutes through a script

I have a output log file which will be continuously appended and I am planning to have a script (runs for every 5 min) to retrieve the last 5 min data from of the output log. Sample data from the ...
0
votes
2answers
116 views

Shell script to kill processes except those owned by user

I am Looking for some help in creating a script to kill processes, but return an error message if they are owned by root. Firstly I would like to say that I am a total beginner at this. At the moment ...
0
votes
1answer
81 views

awk print out file with a row number

I want to print out a file that has 1 column listing values like: cat dog house But I want to have the file print like this to another file: 1 cat 2 dog 3 house I think that awk could be used to ...
1
vote
1answer
58 views

use awk with input from a variable

i need to fetch n+9th line from the occurance of a specific word which is store in variable i from a file LIST.txt Below is the command Used_pages=`awk '/${i}/{nr[NR+9]}; NR in nr' LIST.txt` it ...
0
votes
1answer
45 views

Trying to Use awk by implementating a condition and implication

I have a file containing 8 columns, One of my tasks is to get the values of Column 3 and if the value of the row is not equal to 123 the 8 coloumns will be printed and hence If column 3 is equal to ...
0
votes
2answers
104 views

Command line tool to extract lines from a text file [duplicate]

I have a large file (say reads.fasta) which has around 5,000,000 lines and have another file reads_of_interest which contains a list of the line numbers of reads.fasta that I want to extract. Is ...
1
vote
2answers
27 views

How to parse output for a specific response (creating Extension Attribute for JAMF JSS)

We recently got JAMF JSS for our organization to manage our Macs, and I'm trying to make a script for what they call an Extension Attribute (basically a custom inventory record field). What I want is ...
0
votes
2answers
54 views

Conditional grepping

I have a scenario to handle. Need help with that... I have a config file and its content looks something like below: Jobname|Type|Silo|Description #comment1 #comment2 ...
0
votes
1answer
85 views

Sort multiple csv files based on two columns within a directory

I have multiple .csv files in a directory called mydirectory. I want to sort all these files using some bash/awk/sed command first based on LeftChr column and then RightChr column and get the result. ...
1
vote
1answer
44 views

How do I print all records in file 1 but note the records that do not match file2?

Is there an easy way to print all lines of a file1 (so that the output has the same number of lines as the input file1) but print a message such as NoMatch where the first entries of file1 does not ...
0
votes
1answer
34 views

how to make a file with AWK from different lines

I have a file(pdb)like this: ATOM 1 N LEU A 2 6.630 12.294 -1.457 1.00 0.00 N ATOM 2 CA LEU A 2 7.613 12.686 -0.404 1.00 0.00 C ATOM ...
3
votes
2answers
61 views

How to remove certain characters (but not all) before one or more character(s)?

If I wanted to remove everything before a character (say "("), I would just do something like this 's/.*(//g'. Now I want to remove only certain things before a character/some characters, in my case - ...
6
votes
5answers
629 views

How to abbreviate /path/to/file to /p/t/file

I'm looking for an elegant one-liner (eg, awk) that will shorten a string of a Unix path using the first character of each parent/intermediate level, but the full basename. Easier to show by ...
3
votes
2answers
63 views

Search in specific column for pattern and output entire line

I'm working in HDFS and am trying to get the entire line where the 4th column starts with the number 5: 100|20151010|K|5001 695|20151010|K|1010 309|20151010|R|5005 410|20151010|K|5001 ...
1
vote
2answers
229 views

awk send email if

With the following litte awk script, I get an email notification. But I want to get this email only if $1 is greater or equal than 100. At which position must I put the if statement? I tried many ...
4
votes
5answers
259 views

Print several lines after nth occurence in bash

I'm looking for a way to search for the nth occurrence of a pattern and print k lines after the pattern. I guess awk would work better than grep in this case but I cannot figure out the way to do it ...
1
vote
1answer
161 views

Want to print NULL if value is not present as awk output

I am trying to print a tshark command output using awk below is my command: tshark -r "test.pcap" -odiameter.tcp.ports:"1234" -R 'diameter.cmd.code == 272 and diameter.flags.request==0 and ...
2
votes
3answers
47 views

how to extract a number from the line in unix

I need to find the first occurrence of the attribute ICount and its value must be returned. Only the number from the attribute. How to get it? < FCount = "1" ICount = "0" Ccount= "1"> Please ...
4
votes
1answer
163 views

Script that Outputs the Average of Multiple Group lines, from a File

This is a "Small" portion of the file car_sales.txt that I am trying to extract information from (the full file has about 700 lines, with more vehicle brands than are listed here): ...
0
votes
1answer
115 views

How to write a script that will use a loop structure to process data file?

I have an input file with the following data: November 400 January 200 June 400 March 200 April 200 May 300 July 400 August 300 September 400 February 300 October 300 December 200 I have to make a ...
2
votes
3answers
178 views

Arithmetic on variable containing ip address

I've got variable network="198.168.1.x" # for ex. 198.168.1.254 I want to create new variables: next_serv="198.168.1.(x-1)" # for ex. 198.168.1.253 max_host="198.168.1.(x-2)" # for ex. ...
4
votes
2answers
443 views

How avoid to repeat the same command in bash script

I have this bash script: gunzip -c /var/log/cisco/cisco.log-$(date +%Y%m%d).gz | awk '/ath_bstuck_tasklet/ { print $4 }' | sort | uniq -c > /tmp/netgear_beacon.txt echo "There are `wc -l ...
1
vote
5answers
52 views

awk: Can I find the occurrence of char in given string?

Is there any way to get following result? a c a c a c a a a a a a a a c c c a c 0 0 a c 0 a max a 2nd max c
2
votes
2answers
35 views

gawk: How i can print output genrated by gawk command in multiple line on terminal in single line in file

I am using gawk command to print column content in file like: gawk '{print $2205764, $2205763}' /home/mohasin/fil1.txt It generates output on terminal with new line: a a b b c c d d . . . . I ...
1
vote
1answer
123 views

how to set a variable to multiple values with awk?

I have a file similar to the following : x 0 1 x 1 1 and I am essentially trying to see if both fields are equal to one another or not for every row. But the problem is that this file contains x ...
-1
votes
1answer
39 views

Merge matching lines as one line

I am stuck in awk command to find and merge duplicate lines as one here is how my file looks (I do not have header) and it is sorted on column 2 already: 1, abc, 123, , , , , , , , , , 2, xyz, 123, ...
2
votes
3answers
134 views

Duplicate indexes value in array

Given the files below: file1: 7997,1 7997,2 7997,3 5114,1 5114,2 file2: 7997,52, 5114,12, 4221,52, How can I create an array from the 1st file that has the first column as indices and the ...
0
votes
1answer
31 views

Filter log on final letter in string [closed]

I have a below requirement to filter a word. My logs will be reporting with codes TML2345I,TML8383E & TML9929W. I want to filter the errors only with strings which have the last character as E. ...
5
votes
3answers
67 views

Combine information from two files, line by line

I have 2 files as input: File 1 (space separated) ID POS a0 a1 SNP1 123 A C SNP2 456 T C SNP3 789 G A File 2 (space separated) 0 1 0 1 0 0 0 1 1 1 0 0 1 0 0 1 0 1 1 1 0 0 0 1 Required output A ...
-1
votes
1answer
39 views

How to remove duplicate rows using awk while splitting file

I'm using awk in a shell script so I can split a file according to the 5th column. The code below is similar to the one I'm using: awk -F';' 'NR==1{h=$0; next} !seen[$5]++{f="FILE_"$5".txt";print h ...
3
votes
1answer
233 views

Extract specific columns from text file

There is a text file, with aboot 10000+ lines, in the format: field1 field2 field3 field4 field5 ... fieldX It needs to be converted to look like: field1,field2,field4,field3,field5 to fieldX The ...
4
votes
3answers
155 views

Duplicating a string variable in awk

I would like to precede each line with a number saying how many slashes the line has got. awk '{ l=$0; gsub("[^/]","",l); print length(l),l }' This doesn't work bacause l=$0 seems to assign by ...
6
votes
4answers
181 views

Substitute Column With Result of Command

I'm trying to find a way to quickly and efficiently replace a column value for every row in a file with the output of a command. I need to work on multiple files with about 500,000 rows each daily so ...
3
votes
1answer
30 views

awk not doing a new line

I'm trying to print out the users who are currently logged in (each logged in user of each terminal). This is what I currently have: NOWDATE=$(date +"%Y-%m-%d") NOWTIME=$(date +"%T") USERS=$(who | ...
9
votes
5answers
1k views

Merge two files line by line with the delimiter triple pipe symbol “|||”

I have two parallel files with the same number of lines in two languages and plan to merge these two files line by line with the delimiter |||. E.g., the two files are as follows: File A: 1Mo 1,1 I ...
1
vote
1answer
40 views

Match data from array to data from file?

I'm trying to match up the data from an array the lists the days of the week like this: MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY The files data reads like this: Name1,Tuesday ...
3
votes
1answer
87 views

sed: cut line X and append to top of the file

I would like to be able to cut line X and insert the line X on position y (top). This would help me to be able to reorganize some config files. Text example line number 1 <--- Append line 10 ...
2
votes
4answers
61 views

Remove partial duplicates consecutive lines but keep first and last

I have log files with a time stamp and six values in each line i want to reduce the amount of data, by removing consecutive lines with the same values (ignoring time stamps) and keeping the first and ...
1
vote
1answer
69 views

Replace awk and tr with just awk for converting to lowercase

Not a duplicate question, as I am asking for awk specifically. I have the following command to convert everything to lowercase, and then reprint out substrings in a certain order. cat words |tr ...
1
vote
1answer
223 views

Find and delete lines containing multiple patterns in a file

I have a list of strings and want to find and delete lines containing these strings in a file. A short example of the list of strings is listed as below. File S 1Mo 32,33 2Mo 7,26 2Mo 7,27 2Mo 7,28 ...
2
votes
2answers
50 views

Combine columns using awk? (Or other suggestions)

I'm trying to be a bit effective and need a script or command solution. Say I make a file with 2 columns, or two files with one column, whichever is easier: AA1 B2 ZZ1 YYY XX1 AA2 B2 ...
2
votes
2answers
73 views

Trying to convert a simple C program into an AWK program

Hey guys a couple of weeks ago I wrote a C program that prompts the user for the name of a text file and then prompts the user for a word. The program then outputs the input text file with numbers to ...
3
votes
2answers
48 views

Averaging and moving a selection of files

I have a bunch of directories, each of them enclosing an ascii table named accordingly with the directory name; as follow: a1/a1.txt a2/a2.txt a3/a3.txt a4/a4.txt b1/b1.txt b2/b2.txt b3/b3.txt ...
3
votes
4answers
251 views

How to get Disk space(Avail) using 'df -h' when Filesystem is long

I am trying to find available disk space through console I found df -h | awk '$NF == "/" { print $4 }' to get required output. [root@tmpe2etstmsdc01 ~]# df -h Filesystem ...
4
votes
5answers
95 views

Count unique associated values in awk (or perl)

I've already found "How to print incremental count of occurrences of unique values in column 1", which is similar to my question, but the answer isn't sufficient for my purposes. First let me just ...
1
vote
2answers
148 views

Using awk and grep for iftop results

I wanted to monitor my server network send and receive rate using iftop. This is what works for me: iftop -t -s 1 -n -N | grep 'Total send and receive rate: ' | awk '{print $8}' Mac address and Ips ...
1
vote
1answer
70 views

How do I keep awk variables in scope?

I am attempting to keep track of the lowest/highest values from a list of counties and populations. I can't figure out how to stop variables from resetting themselves at 0. This is my cmd.awk ...
5
votes
1answer
219 views

Sort output of awk except for first line?

This is a use case I am continually running into in parsing CSV files. When it is an inline awk script embedded in a shell script, I can use this workaround: myfile=$(mktemp) awk '(awk script here)' ...
1
vote
1answer
85 views

Nesting Awk and variable comparison [duplicate]

I found myself having to learn a bit of awk, and it's really cool, but I have a small problem I am facing. I have a script that has an output that is designed to be piped. Let's call it matrix. I ...