Questions tagged [awk]

The AWK utility is a data extraction and reporting tool that uses a data-driven scripting language consisting of a set of actions to be taken against textual data (either in files or data streams) for the purpose of producing formatted reports.

Filter by
Sorted by
Tagged with
0
votes
1answer
24 views

Can Linux do conditional judgment to insert the content at a certain line in Linux

Can Linux do conditional judgment to insert the content at a certain line in Linux? For example, I would like to add user "test" to /etc/sudoers to let it can switch to root: 1 # 2 # ...
0
votes
1answer
153 views

sed: customizing config file header with a defined length?

I use sed to customize LXC container configuration files from the LXC host. That works well so far. When adjusting comment headers (hostname and date), there are aesthetic problems with the width of ...
0
votes
2answers
54 views

Awk script to filter text output to single line

I have a script that is giving me an output like this: ruby-devel is needed by software1 tcl is needed by software 2 python3 is needed by software 3 ocaml is needed by software 1 I'm new to awk but ...
2
votes
1answer
249 views

Extract a ids from text file

I have a text file live below { "data": { "assigned-entity-id": null, "assigned-entity-type": null, "availability-domain": null, "...
0
votes
1answer
35 views

Finding a string and remove all contents between two delimiters

I have searched and I don't know what I'm doing wrong but I can't find an answer to this question. I have a file with all text stored as a single line. I am needing to find a pattern and remove all ...
1
vote
1answer
26 views

Misaligned AWK output

I have simple awk command generating output and then sending an email: awk '(NR==FNR){a[$2]=sprintf("%.2f",$1*value); next} {print $1,$2,a[$2]}' OFS="\t\t\t" value=$COST /tmp/1.txt ...
1
vote
1answer
52 views

Format export using grep and awk

I would like to export data from zimbra server, but it's export data in every new lines, my command: zmprov -l gaa -v domain.com | grep -e "zimbraForeignPrincipal: " -e "...
0
votes
0answers
59 views

AWK to read multiple files in linux without duplicates

I have a task to merge three files in linux, so i used awk to achieve this task. hostsfiles is a variable which has test.txt test1.txt and test3.txt awk 1 {{ hostsfiles | join(' ') }} I get below ...
0
votes
1answer
23 views

Multiply first column by variable depending on unit

I have du -sh output saved to txt file: 2.1G /home/x/sample/2GB/ 101M /home/x/sample/100MB/ ... What I want is to multiply each value in the first column by a value taken from variable ...
0
votes
1answer
22 views

Find all words after specific string

So, here's the thing. I have a file contains like this: LOG=123 HEY=BRO FOO=BAR LOG=124 I need the value of LOG= and an output like this: 123 124 I already tried using this command: echo "$LOG&...
-1
votes
1answer
877 views

How to remove text after a 4 digit year in a file name

I am looking to remove all text after the 4 digit year of movie files: Input: Some.Movie.Name.2011.1080p.BluRay.x265.mp4 Another.Movie.Name.1999.1080p.BluRay.x264.mp4 Another.Movie.Name.II.2001.1080p....
0
votes
1answer
112 views

left outer join 2 shell output on a common key column using bash

Is there a way I can do a "left outer join" for bash output from 2 different commands based on a common key column (ip address)? For various reasons, I would like to avoid saving the output ...
0
votes
1answer
207 views

How to change one line of code in a block of code from linux command line?

I have a change I need to make across multiple different sites and may need to make again in the future, so I'd like to put it in a shell script. Essentially I want to find a specific class block in a ...
0
votes
2answers
95 views

nethogs -t | awk '{print $0}' return no output

nethogs is a linux process bandwidth monitoring tool. https://github.com/raboof/nethogs nethogs -t it's output looks like this. Refreshing: sshd: root@pts/0/4002/0 0.185156 0.0773437 unknown ...
0
votes
1answer
694 views

How to separate variables using awk and append it to Text file using ansible

What I got as extra variable to ansible playbook is "CHOW_app/timmy_app1/johnn_app3/harper_app4/mona_app5". This is passed as single variable to the playbook. I have to separate it and save it in a ...
0
votes
1answer
28 views

How to grep lines only with matched words in Linux [closed]

I have a little question. I have a list of processes. After this command ps aux | grep postgres I see postgres 1178 0.0 0.2 320064 27060 ? S Apr12 0:05 /usr/lib/postgresql/10/bin/...
0
votes
2answers
716 views

uptime | awk -F: '{print $NF}' - What happens here? [closed]

Can someone explain me what happens here? uptime | awk -F: '{print $NF}' -F: field separator $NF: number of fields in the current line I don't understand why this command result in the same result ...
0
votes
2answers
94 views

Extract string from column with grep

I have a column based .txt file and I want to grep output the Common Name, having a little trouble. V 300223164711Z 01 unknown /C=UK/O=LMG/OU=server/CN=server/name=server/emailAddress=...
0
votes
1answer
32 views

How to print only Users list and Access level from /etc/sudoers?

We have multiple servers and i would like to print users list and access level using bash. I tried below command but could not get exact result what i wanted to: awk '/Allow root/{p=5} p > 0 {...
0
votes
2answers
647 views

How do I cut just the file name from from ls -l output? [closed]

I am in the process of concatenating ogg audio files in bulk with the help of ffmpeg using a mylist.txt file The format of the mylist.txt file is file '/path/to/file1.wav' file '/path/to/file2.wav' ...
0
votes
1answer
130 views

Convert date and time from output

I have a file with date and time on a couple thousand lines. I need to convert: 2019/08/02-01:23:50+0000 To: 02/Aug/2019-01:23:50 +0000 I so far have th=`grep ...
0
votes
1answer
69 views

Convert date format in file

I have a file with the current date format 11.22.33.44 - - [2019/08/02-01:23:50+0000] GET www. 1111:2222:3333:4444:5555:6666:7777:8888 - - [2019/08/02-01:28:18+0000] GET www. And i need to convert ...
2
votes
3answers
2k views

CentOS 7 how to get interface name by macaddress?

I'm trying to figure out how I can get the network interface name and then change the name. Right now it's easy to change the name with this example: ip link set eth1 name <newName>; However I ...
5
votes
2answers
10k views

How to make in SSH private key from one line, three lines [closed]

i have ssh-key, something like this -----BEGIN RSA PRIVATE KEY----- my_super_secret_password -----END RSA PRIVATE KEY----- Of course this key does not work. When i am doing manual things, something, ...
2
votes
2answers
1k views

How to add the filename as prefix to each line of the text file? (batch processing; subdirectories)

I have many .txt files with their filenames being different dates: 01.01.2010.txt 02.01.2010.txt ... Currently each file (e.g.: 01.01.2010.txt) looks like this: 0.351 XXX XXX XXX XXX 0.292 ...
0
votes
2answers
44 views

sed/awk - find match by one string and change different string on the same line

this should be easy question for most of you but for me. I need to perform some text operations above json a yml config files, which contains definitions of some channels - structure of every line is ...
0
votes
2answers
249 views

Can't redirect awk output to a file... tried everything

I created a nice little command to measure data bandwidth consumption over a metered connection (excluding local traffic): sudo iftop -i enp1s0 -f 'not (src net (10 or 172.16/12 or 192.168/16) and ...
1
vote
3answers
50 views

text processing linux using grep awk or anything else

I want to replace in this string Wed Apr 10 06:44:10 UTC 2019 all whitespaces with comma and along with that trim off UTC part. What I have tried : var1="Wed Apr 10 06:44:10 UTC 2019" echo ${var// /,...
0
votes
1answer
79 views

get a specific line from in linux using grep

Hello I am new to linux and grep and awk commands. I am trying to get the number value from this string variable and then store it in another variable. var1="Version must be incremented on update. ...
0
votes
0answers
177 views

chkrootkit awk not found

I am using chkrootkit 0.53 on my ubuntu dekstop 18.04 When I was doing scan with ` ./chkrootkit -p /folder it give me error chkrootkit: can't find 'awk' . Could anyone help? Thank you
0
votes
1answer
272 views

nmap output in csv format sorted by last octet in ip address

I have this command which works well to give me a list of ip address, MAC address, and Mac Vendor sudo nmap -sn 192.168.0.0/24 | awk '/Nmap scan report for/{printf $5;}/MAC Address:/{print " "substr($...
0
votes
2answers
49 views

Extract text between 2 strings only if another string is present

I have a quit large XML file that I am trying to modify only certain lines of the file. The lines I want to modify will all contain in them. On those lines, I want to have only the text between 2 ...
-3
votes
1answer
56 views

searching file for last matching line, then put 3rd word of this line into a variable

i have a logfile, a script checks this log-file every hour it shall pack the 3rd word of the last matching line into a variable but i didn't manage it to work yet .. logfile: 2018-11-18 22:27:10 ...
2
votes
2answers
133 views

AWK help filter data into CSV

We are doing some security research for which I need to extract from Debian repos all available package names, versions, desc, etc. I'm trying to parse output of apt-cache dumpavail into CSV and ...
0
votes
1answer
343 views

Using sed to remove "(double-quotes) on code lines while leaving them on real comments in a vimrc [closed]

I'm finally learning how to use sed to edit configs while installing Ubuntu(Server/Desktop). After much gnashing of teeth and searching about for the proper syntax to not remove the "(comment double-...
1
vote
1answer
306 views

regex: match two /'s back from end of line [duplicate]

I have a file of file paths. The depth of the directories is of various lengths and path names. I'd like to match two directories backwards (two /'s) and delete the match, creating a new file with the ...
0
votes
1answer
37 views

delete some char set from the last column linux

I want to the delete everything after hyphen "e-" in the last column output.. Below is what my output looks like.. # awk '/out: OpenSSL/ { gsub( /[][]|out:/ , "" ) ; print $1,$2,$3 }' sslcheck.log |...
0
votes
0answers
811 views

sed + delete duplicate lines except the first one according to specific request

in /etc/services file I can see duplicate lines for example the following line is duplicate ( or more ) odasrv 2432/udp so it can easily deleted by sed as the follwing sed -i '/codasrv ...
1
vote
1answer
2k views

How can I use an iperf output and only grep Interval and Bandwidth?

I am trying to get the output from the command iperf -c 10.0.0.1 -t 3600 -i 2 And only need the Interval and bandwidth fields listed for the entire hour of logging. I haven't used grep or awk in ...
-1
votes
1answer
545 views

How to pass variable into bash script and use seperate variables with awk?

I have a script that I am using to clear out all lines of a log files older than X days. X can be passed in via command line as well as the log file name, ex usage: ./purge-catalina.sh 3 /opt/...
1
vote
3answers
1k views

Grep last match from file

I'm running the following command against a log file and only wanting to get the last/latest match. Sometimes there may only be one match, other times there may be multiple, which is causing an issue ...
7
votes
5answers
6k views

Calculate sum of several sizes of files in Bash

I have list of files in a file, cache_temp. In file cache_temp: /home/maildir/mydomain.com/een/new/1491397868.M395935P76076.nm1.mydomain.com,S=1740,W=1777 /home/maildir/mydomain.com/een/new/...
4
votes
2answers
601 views

How to show specific luns from lsscsi command?

I need to grep specific luns from the lsscsi command. For example: [root@e15l1 ~]# lsscsi 4 0 1 | awk '{print $1,$6}' | head [4:0:1:0] - [4:0:1:1] /dev/sdab [4:0:1:2] /dev/sdj [4:0:1:3] /dev/sdz [4:...
1
vote
2answers
272 views

How to extract the last two (or any number) directories from a path with sed?

I'm really looking for a generic solution here, but for the sake of example, let's say I'm looking for the deepest 2 directories in a path. e.g.: Given a path /home/someone/foo/bar, how can I use sed (...
0
votes
2answers
856 views

replacing space with new line characters for vagrant box use

I am trying to setup vagrant box using shell script where in I am storing key and cert files. Normal format of any cert or key file is as below -----BEGIN CERTIFICATE----- ...
-1
votes
1answer
123 views

validate file content with bash Regular Expressions + Linux

how to validate the following file content that should be include single integer/float number by bash Regular Expression or any other idea with awk/sed cat /var/VERSION/Version_F35_project_usa 2....
0
votes
2answers
456 views

How to insert a complex line between two single quotes in sed?

I have this line in the file /var/lib/pgsql/data/postgresql.conf: # archive_command = '' # command to use to archive a logfile segment we need to uncomment the archive_command parameter, ...
1
vote
1answer
418 views

multiline into single line and output to logger

I have a log file where data entries are as follows Each entry starts with time: time: 20170509123420 dn: uid=abc,ou=People,dc=test,dc=example,dc=com changetype: modify replace: ...
1
vote
2answers
280 views

How to retrieve first N and last M lines from input in fish?

I have an input like: 1 2 3 4 5 6 7 8 And I'd like to retrieve only N first and M last lines from this input. For example, if N is 2 and M is 4 I want the result to be: 1 2 5 6 7 8 Lines can ...
-1
votes
1answer
89 views

how do i remove local ip from list of ip addresses?

I have a variable that contains list of ips and i will like to remove the ip of the instance where the variable is set Please see below [root@ip-10-10-2-100 ~]# INSTANCE_IP=$(curl -s http://169.254....