Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [awk]

AWK is a text-processing language. It is mainly used to manipulate and process structured data, and to generate reports.

0
votes
1answer
41 views

Replace lines after a given number of matches on separate lines with AWK

Currently I'm using AWK to find and replace a portion of a string after the first three occurrences of a pattern. The string is formatted like this: func(tempID="39849235",count='12');, and there are ...
0
votes
2answers
31 views

How can I get quotes to show up when I'm using AWK to find and replace?

Currently I'm using AWK to find and replace a portion of the first three occurrences of a string. The string is formatted as such, and there are many of these strings in the file: func(tempID="...
-1
votes
1answer
20 views

Manipulating output - awk|sed|grep

I would like to maniputate the following output like this: Output: S* 0.0.0.0/0 [1/0] via 1.1.1.1, MAR-LNK-VGL_DSL [1/0] via 2.2.2.2, MAR-LNK-GVT_DSL [1/0] ...
2
votes
2answers
83 views

Find Missing Numbers

I have a big list of files with names (videos) I managed to write all file names in a text file. Now I have a text file with a lot of file names (one episode per line) Now I need something that can ...
0
votes
1answer
31 views

Delete row with empty line csv

1 1479870 5022248660 1 1911574 3015889020 8 1 1569783 5029193930 Output should be 1 1911574 3015889020 8 I used awk '$4!=""' number.csv but it didn't work. Can anyone give me a clue?
0
votes
0answers
22 views

AWK/TAWK translate parameters

I came across some old AWK files that I need to convert (or at least make use of the logic already designed), and most of it I can understand and/or reverse engineer. There are however a few lines ...
0
votes
1answer
23 views

How characters can be inserted to strings belonging to a column resulting from an intput command using awk and sed

Here is a formula that has appropriate foundation for my purpose – among others it prints files only, using for sizes powers of 1024, 2^10 –. Involved file's size is 1382 bytes (1,35 KiB): # ls -lh | ...
0
votes
3answers
55 views

How do I return from an awk script back to the command line?

I have a simple awk script, test1.awk: { x=temp; print x; } When I run it from the Command Prompt with: awk -v temp=hello -f test1.awk I get just a cursor.  I hit Enter, it writes “hello” ...
1
vote
1answer
66 views

How can I sort the output of awk, disregarding a certain character?

I am trying to print out the Chinese font I have in my laptop, and sort the output with respect to their name that could be referred to in LaTeX. This could be done with the following command: fc-...
0
votes
1answer
55 views

Using `ls` to show real name of file owners

Unix users can have their real names listed in /etc/passwd/. The finger command can display the real names. Can ls -l show these real names of file owners next to the files? If ls cannot do this ...
0
votes
0answers
70 views

Lookup-table text replacement in bash

We have weird usernames in our Linux system (like user0001). I would like to pipe results of ls -l through a lookup-table replacement of the weird usernames by their real names. I can make such a ...
2
votes
2answers
35 views

replace number with star specific pattern for whole file

In my file I want to replace number to * Example: data[0] ---> data[*] I have data[0] to data[127] and also want to do for the whole file. So how can I do only for number? I tried with command ...
0
votes
0answers
30 views

make apt-get less verbose

I´m on Debian 16.04 and built myself a shell script to simplify all the update stuff and I regularly call it with sudo: apt-get -qy update apt-get -qq upgrade apt-get -qq dist-upgrade apt-get -qq ...
0
votes
1answer
38 views

How to convert “yyyy-mm-dd” to “dd.mm” in column of text file using awk (or sed, etc.)?

Let's consider that we have the following line in text file: ... 2018-09-13 5555 33-33 Some_string ... I need to change first column (date as yyyy-mm-dd) to other format (dd.mm, dropping ...
1
vote
1answer
26 views

mac: concatenate contents of text files across many directories; append directory names to corresponding text file contents

In the following directory structure: directory1 -subdirectoryA ---fileA.txt -subdirectoryB ---fileB.txt subdirectoryC ---fileC.txt I would like to generate a text file containing the following ...
2
votes
1answer
41 views

Take a file of regexes and return the first match for each in another file

I have two files. a.txt has a list of regexes, separated by newlines. b.txt has lines, some of which match the regexes in a.txt. What I want: A command (grep, probably) that will take the two files, ...
0
votes
1answer
40 views

How to use sed to remove "(double-quotes) on code lines while leaving them on real comment lines in a vimrc file?

On Ubuntu(Server/Desktop), I wish to remove a single " (double quotes) character from the beginning of lines in my /etc/vim/vimrc. This should be done for all lines that start with a ", but not if ...
3
votes
1answer
42 views

How to get a specific string value from an Apple System profiler SPHardwareDataType

I'm using Bash to rename computers en masse using a part of the serial number, which is pretty easy, but my client has requested that the manufacture year of each machine be appended to the end. ...
1
vote
2answers
64 views

Remove First 8 columns from ls Output with AWK

I would like to use AWK to remove the first 8 columns from the following output: ls -l lrwxrwxrwx 1 user user 23 jul 27 00:04 file1.pdf -rw-rw-r-- 1 user user 107 may 8 13:59 file 2 with spaces....
2
votes
2answers
59 views

How do I transpose a table with repeated key values?

I have a table that looks like this: Column A | Column B 10 | 0.1 10 | 0.2 10 | 0.3 20 | 0.4 20 | 0.5 20 | 0.6 I need to transpose ...
0
votes
1answer
56 views

Why is awk sub not replacing my input

I have been struggling to write an awk program that would take input files and display the original and space separated filename only in second column. Why is the following command not working for ...
0
votes
1answer
56 views

How to create multiple html tables from multiple csv files using a shell script

I have two csv files like this: test1.csv: user size aaa 10 bbb 20 ccc 30 test2.csv: name value www 5 mmm 8 ppp 9 I want to convert this to two separate HTML tables using a shell ...
0
votes
2answers
859 views

how to extract json file using awk/sed?

Input data.json { "lastUpdateTime" : "2018-07-20T10:56:26.000Z", "items" : [ { "date" : "2018-07-19T21:09:27.000Z", "user" : "dddd", "size" : 5219402, "rawSize" : 15658206, "...
0
votes
1answer
79 views

Awk , but print only a portion of a field

I am concerned with only a portion of a particular field (hostname) in a log line and would like to print all the unique occurrences of said portion. I am currently doing something like: zcat $...
0
votes
1answer
148 views

How to compare two columns of two different files

I have two file.The first one contains something like: a.com,5,some,text b.com,10,some,text c.com,5,some,text d.com,12,some,text e.com,5,some,text c.com,5,some,text The second contains something ...
0
votes
2answers
53 views

How to search a string starting from second column

I have a file that contains comma separated strings. The strings may contain dots (i.e. not just alphanumeric characters). This is an example: site1.com,Level1.2 site2.com,Level1.1,Level1.0,Level1.2 ...
0
votes
1answer
32 views

a loop in awk command

I have a file with the following input data: Sample1 Feature 1 A B C D Feature 2 E F G Sample2: Feature 1 H I Feature 2 L O P And I would like to have the following output: Sample1 Feature 1: 4 ...
0
votes
1answer
119 views

Package not found for awk.exe and csh.exe in Cygwin 2.10.0

I'm upgrading from cygwin 1.7.35 to cygwin 2.10.0. But I could not find any package that contains awk & csh binaries (.exe). When I type info csh or info awk in cygwin(2.10.0) terminal it shows ...
1
vote
2answers
316 views

How can I output iperf results for only 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 ...
0
votes
1answer
34 views

How do I split a string at an occurrence of a character in shell using set and awk?

I am using an embedded version of shell. And I need to split a string using set and awk? NO BASH PLEASE. How do I do this? The following script is not complete and spells out wrong output. #!/bin/...
0
votes
1answer
35 views

Extract, sort and save data from multiple files into one

I have multiple .sie files, The SIE format is an open standard for transferring accounting data between different software produced by different software suppliers. of which I want to extract ...
3
votes
1answer
64 views

Add specific text in every blank line

I've a file as below abc pqr xyz aaa bbb ccc I want to add specific text like "this is test" in every blank line like below abc this is test pqr xyz this is test this is test aaa bbb this is ...
1
vote
2answers
102 views

Search a line(string) between other two diferent lines

I'm searching for one liner command (in best way) that can find if specific string/line is presented between other two lines. I search for it and I only found commad to get content between two lines, ...
-2
votes
2answers
157 views

find string and check for second

Every file have first line that start with a 1 b followed by unknown_string and remaining lines starting with c followed by unknown_string I want to check the string AFTER the a 1 b is present in any ...
0
votes
2answers
534 views

How to parse multi-line log file in awk and output only single line with last known ip address

I am stuck and looking for assistance. I want to trigger an event which I'd like to process further through a bash script. The data is retrieved from a log file. Before I start to explain I'll show ...
1
vote
0answers
72 views

How to change the highlight in Notepad ++ for variables in double quotes?

How can I change the highlight for the variable that in the double quotes with Notepad ++? I would like have the variable "$1" like in the example if [ ! -z "$1" ] and all the others within double ...
0
votes
0answers
29 views

Tagging “first matching entry on each day” from a list of records, using standard *nix tools

I have a text file that contains records of the form: text text <2018.02.20-13.05.22> [dataset-london] text text text text text <2018.02.20-13.05.25> [dataset-newyork] text text text text ...
0
votes
1answer
221 views

Double quotes in a specific column using awk or sed

I have this input: ##gff-version 3 chr1 TAIR10 mRNA 3631 5899 . + . ID AT1G01010.1 ;geneID AT1G01010 ;gene_name AT1G01010 chr1 TAIR10 exon 3631 3913 . + . Parent ...
0
votes
2answers
271 views

Sum all lines of a csv file

I have got a .csv files, with some numbers, I want to get a new file with the same number of rows and one column, with the sum of the numbers of the corresponding row in the original .csv file. Input ...
0
votes
1answer
39 views

Sort a table based on a column with string mixed with numbers in bash

I have a txt file with the below table 3-6-13 0.0712 ./13-t.xyz 3-6-13 0.0717 ./2-t.xyz 3-6-13 0.3737 ./6-t.xyz 3-6-13 0.5862 ./5-t.xyz 3-6-13 0.7503 ./4-t.xyz how can I sort it based on ...
1
vote
1answer
27 views

Shell Script to look for all lines in a file having '500' in the 11 column taking too long to run

I wrote the following script as a practice : #!/bin/bash MyFile=$1 while read p; do error=$(echo $p | awk '{print $11}') if [ "$error" = "500" ] then echo $p ...
2
votes
1answer
56 views

Text processing: transforming numbers in equivalent number of spaces in bash

I have a file containing strings with embedded macros like int main() { $(3) return 0; $(0) } The sequence of characters " $(n) " should be replaced by n white spaces and the end of line character, ...
5
votes
5answers
564 views

How to chain awk print statements?

Okay, here's a quick example; me isolating a host's IPV4 in three steps: ip -br a lo UNKNOWN 127.0.0.1/8 ::1/128 eth0 DOWN wlan0 UP ...
0
votes
2answers
91 views

linux: how to capture the number/s from string

I use the following syntax in order to capture only the number from machine hostname echo machineLinux05 | sed s'/\./ /g' | awk '{print $1}' | sed 's/[^0-9]//g' 05 But this way is not so elegant. ...
1
vote
1answer
449 views

How to extract a segment of a binary file based on starting and ending hex strings

I have a large binary file (several hundred GBs) and I want to extract a segment from it. I know the hex strings of the beginning and ending points.
0
votes
1answer
33 views

select data based on value of a field

I have a file with several entries providing IDs and another file with other entries subdivided in different fields separate by a TAB. I need to select the records of the second file based on matching ...
0
votes
1answer
124 views

Break down the following bash script?

I need help breaking down the following bash script, to understand what the author was trying to do. The script is meant to search a log file for data and then compare it to an email log file. ...
1
vote
1answer
124 views

Getting AWK error while transpose some message content

I trying to transpose below text into single line with pipe separated, i getting some error if text is start with number% , what is the issue, any other command is there Sample content in txt file ...
0
votes
3answers
1k views

search in log from last hour

I need bash script to search in the log words Failed and failure. But only from last hour cut -c 5- /var/log/mail.log | awk '($0 >= from)' from="$(LC_TIME=C date +'%_d %H:%M:%S' -d -1hour)" |grep -...
1
vote
4answers
123 views

Linux Extract Matched Text Field from File

I have a file which has many lines of the format: bc("STG1/Phone") = {type=bana_pub; cbb=12.354; abb=0.0}` I'm looking to extract cbb=12.354;. Currently, I'm doing the following: cat input_file....