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.

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. The language used by awk extensively uses the string datatype, associative arrays (that is, arrays indexed by key strings), and regular expressions.

AWK was created at Bell Labs in the 1970s, and its name is derived from the family names of its authors — Alfred Aho, Peter Weinberger, and Brian Kernighan.

194 questions
0
votes
1 answer

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 the headers, since when the hostname with…
questor
  • 1
  • 2
0
votes
2 answers

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 was trying to script it to get the first word, and…
Emersonjr
  • 11
  • 2
0
votes
1 answer

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 the text before and after that text until…
0
votes
0 answers

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 error. How do i avoid the error when any one of the…
celcoprab
  • 43
  • 2
  • 3
  • 8
0
votes
1 answer

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 depending on the unit. So if for instance unit is G then…
DisplayName
  • 145
  • 4
0
votes
1 answer

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" | egrep -o 'LOG=.*' but it only outputs everything…
Azikun
  • 3
  • 1
0
votes
1 answer

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.BluRay.x264.mp4 Desired…
0
votes
1 answer

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 from either commands into a file and using the filename as…
louis xie
  • 125
  • 1
  • 5
0
votes
1 answer

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 css file, find one of its attributes and change…
TBridges42
  • 101
  • 2
0
votes
2 answers

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 TCP/0/0 0 0 Refreshing: sshd:…
The Unix Janitor
  • 2,458
  • 15
  • 13
0
votes
1 answer

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 text file in this format. REVOKE CHOW app REVOKE…
saffron
  • 143
  • 1
  • 3
  • 12
0
votes
1 answer

How to grep lines only with matched words in Linux

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/postgres -D /var/lib/postgresql/10/main -c…
Piduna
  • 541
  • 4
  • 12
  • 25
0
votes
2 answers

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

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 as uptime | awk -F: '{print $5}'
Mike
  • 103
  • 1
  • 5
0
votes
2 answers

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=support@kam.org V 300223170002Z 02 unknown…
Kam-ALIEN
  • 19
  • 5
0
votes
1 answer

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 {print $1; p--}' /etc/sudoers above command just give…
Santosh Garole
  • 453
  • 1
  • 4
  • 11
1 2 3
12
13