awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

-1
votes
1answer
33 views

Trying to sum a decimal column from a csv file for each different vendor

I am new to Unix/Linux and am trying to sum a column for each vendor in a loop. I apologize for the vagueness. I will try to explain. It is suppose to read from a file and based on the vendor name ...
0
votes
3answers
35 views

Matching lines in two files [duplicate]

Let's say I have two files, file1 and file2. file1: passd:xxx hopla:alli gnar:gungg araf:utap file2: alli utap How can i check what lines/words from file2 match file? Indeed I could probably do ...
1
vote
1answer
27 views

Matching 2 main columns between files; and paste other columns into the output file when those main columns match. Keep row size of 1st file intact

This is a follow-up question to my previous question asked about 24 hours ago. Link to previous question: Previous Question Link G-Man solved that problem with a useful code, but I have a follow-up ...
2
votes
1answer
69 views

Matching two main columns at the same time between files, and paste supplementary columns into the output file when those main columns match

I have 3 files, each with a unique number of columns, all tab-separated, but some columns are shared between the 3 files. It's the shared columns between the 3 files that I want to use to create some ...
0
votes
1answer
39 views

awk script to extract the argument of an option

Can some one explain what the awk '{for(i=1;i<=NF;i++) if($i~/-f/) print $(i+1)}') part does in the following snippet line='/wwws/apache/apache2.4.16w-r01/instroot/bin/httpd -f ...
4
votes
4answers
121 views

Use awk interactively through a pipe

Looking at this question, I've noticed that awk can't read user input if the file is being piped into standard input, but it does behave as expected if reading input from a file given as a command ...
-4
votes
1answer
30 views

I'm using the following snippet for Log rotation

Can some one explain how this worksps -ef | grep mongod | awk '$0!~/grep/ && $2~/[0-9]/{print "kill -SIGUSR1 "$2}' | bash; find /tmp/logs/* -type f -mtime +7 -exec rm {} \;
0
votes
4answers
40 views

How to remove a first character of that particular sentences from a list of output [duplicate]

grep /var/log /etc/rsyslog.conf | awk '{print $2}' Output: /var/log/messages /var/log/secure -/var/log/maillog /var/log/cron -/var/log/spooler /var/log/boot.log I want the result to be: ...
1
vote
0answers
36 views

Unix: C-shell:Disk space checking in Hp-UX

i have 10 devices that using hp-ux and i want to check the disk space in each devices. my requirement is if the space more than 90%, the info of device ans space will be save to a log. this is list of ...
1
vote
2answers
52 views

awk print to file

I have a big c file that gives a lot of output that I don't care about right now. I wrote this awk script to do mostly what I want. Not sure how to put the finishing touches on it. I would also like ...
4
votes
1answer
55 views

How to use Awk to format numbers with a thousands separator

Can anyone tell me how to use the awk command for this statement "the number will contain commas after every three digits. For example, 100000000 will become 100,000,000." I know how to use sed ...
0
votes
1answer
28 views

writing of user's input with loop into text file

echo -n "##### STATIONS? #######" read station awk -v input="$station" ' BEGIN { n = split(tolower(input), user) fmt = "%-4s\n" } {print} /stab_site clear/ { for (i=1; ...
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 ...
3
votes
3answers
76 views

Print all matching lines and the previous unindented line

For example, lets say I want to find all lines with 'matching' and the previous unindented lines in this text. Container 1 some text some text matching text some text Container 2 some ...
1
vote
2answers
40 views

Parsing with awk by modifying the field and record separators

I have a file which is as follows: ------------------------------------------------------------------------------------------------------------------------------------------------------------------ ...
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 | ...
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. ...
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 ...
1
vote
1answer
55 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 ...
1
vote
2answers
70 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 ...
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
72 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
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 ...
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 ...
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
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 - ...
7
votes
5answers
607 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
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
1answer
69 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
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 ...
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): ...
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 ...
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
46 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 ...
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
2answers
32 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
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, ...
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 ...