awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

0
votes
1answer
30 views

Make new line above last line and add something there

Like a reverse of awk 'NR==2 {print ""} 1 which adds a new line under the first and prints whatever there. I can't replace the number after NR== with a fixed value because I want to be able to do this ...
0
votes
0answers
25 views

Canvas(blackboard)-like program

I have to make a program that has most of the functions those websites have and I am stuck at the point where I have to get the grades from a file and use a formula to calculate the students final ...
1
vote
1answer
55 views

Inserting variables in a command within a shell script

I'm attempting to write an automated script which will update the IP address for my Raspberry Pi within my /etc/hosts file. I'm able to execute this line just fine, IP=`sudo nmap -sP 10.61.4.0/24 | ...
1
vote
2answers
40 views

Parsing with awk by modifying the field and record separators

I have a file which is as follows: ------------------------------------------------------------------------------------------------------------------------------------------------------------------ ...
8
votes
7answers
16k views

Print odd-numbered lines, print even-numbered lines

I want to print the odd-numbered and even-numbered lines from files. I found this shell script which makes use of echo. #!/bin/bash # Write a shell script that, given a file name as the argument ...
0
votes
3answers
8k views

Replacing one test string with another in particular column

I would like to replace "CC" with "C" and "AA" with A" in a particular column of Tab delimited file (using awk probably).
9
votes
3answers
2k views

Print a line only if the next line does NOT contain a particular match

I am trying to search a log file for logged activities that did not complete. For example, I log a "Starting activity for ID 1234..." and if successful, the next line will be "Activity 1234 ...
2
votes
1answer
168 views

GREP exclude first 11 values

I have a massive log file that I need to filter. In this log, I want to display all logs that contain the string dns and I want see them just once. i.e from this: Dec 9 07:24:02 94.15.218.140 ...
1
vote
1answer
23 views

How to see the lines whose date column is less than x day from today

My file ID=29524 02/12/2015,23:59:34,'PAt, 0, ID=29628 02/12/2015,23:59:37,'PAb, 1.9, ID=30816 03/12/2015,00:00:20,'PAc, 4.15, I would like to print files with X days less than from today. My try ...
0
votes
2answers
65 views

Search for a specific word in each line and print rest of the line

I have text file with server URL lines like: request get https://abc.net/search?q=hello/world/hello/word/search=5&size=10 request get https://abc.net/search?q=hello/world/hello/world/hello/word=5 ...
1
vote
3answers
57 views

How to sort blocks of lines with a specific line from the block?

I have a file with the data like this BEGIN hello2 5 world1 END BEGIN hello4 2 world5 END BEGIN hello6 4 END I want to sort the lines in the following manner based on the number inside the block. ...
1
vote
1answer
56 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
34 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 ...
4
votes
3answers
513 views

Extracting unique piece of text from file with awk, sed or grep

From the output of pactl list sink-inputs, I need to grab the sink input number for VLC. Before that, I'm trying to extract the piece that contains the output for only VLC. All the methods that I ...
1
vote
2answers
71 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
43 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 ...
0
votes
2answers
48 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 ...
2
votes
1answer
36 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 ...
1
vote
1answer
42 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
73 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 ...
0
votes
1answer
46 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
2answers
17 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 ...
1
vote
1answer
43 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
29 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
54 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 - ...
3
votes
2answers
32 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
68 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
198 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
2answers
902 views

pattern search and display the last occuring pattern?

I have a log file containing startup and shutdown times for everday. I want to see the last pattern for startup and shutdown (which is located at the end of the file being updated everyday). Also I ...
2
votes
3answers
43 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 ...
0
votes
1answer
66 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 ...
4
votes
1answer
86 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): ...
2
votes
3answers
132 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. ...
1
vote
1answer
48 views

Need To grab IP of visitors from the Apache logs , How could I do it?

I want to store the IP of the visitors to my website, I want to use PHP , Should I use cron for it or how will be the visitors IP will be automatically stored ??
4
votes
2answers
420 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 ...
9
votes
5answers
898 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
5answers
50 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
3answers
124 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 ...
11
votes
7answers
11k views

How to insert the content of a file into another file before a pattern (marker)?

File1 contents: line1-file1 "1" line2-file1 "2" line3-file1 "3" line4-file1 "4" File2 contents: line1-file2 "25" line2-file2 "24" Pointer-file2 "23" ...
1
vote
1answer
35 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
35 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, ...
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. ...
6
votes
4answers
141 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 ...
5
votes
3answers
61 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
32 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
89 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
137 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 ...
13
votes
7answers
21k views

Remove comma between the quotes only in a comma delimited file

I have a input file delimited with commas (,). There are some fields enclosed in double quotes that are having a comma in them. Here is the sample row 123,"ABC, DEV 23",345,534.202,NAME I need to ...
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 | ...
1
vote
1answer
62 views

expand data based on scores

Firstly I have a set of valid combinations of 3 columns (validlist), so the final result must be a subset of this file. a b c c b c p b d d y d p y d x y z I have a score ...